Embed browser in Java based desktop application [d

2019-01-18 14:15发布

Possible Duplicate:
Is there a way to embed a browser in Java?

How can I embed a browser in a Java based desktop application? Can I communicate with the embedded browser directly (not via localhost)... such as loading html text, capturing onclick events, getting form values?

Thanks

6条回答
Juvenile、少年°
2楼-- · 2019-01-18 14:30

You can build a very primitive browser using JEditorPane. You can listen to Hyperlink events, but javascript or getting form values isn't possible.

查看更多
放荡不羁爱自由
3楼-- · 2019-01-18 14:34

Swing JEditor pane is able to display HTML.

Check http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html

Also here in SO is a more detailed answer to this topic:

https://stackoverflow.com/questions/48249/java-embedding-a-web-browser-pane

查看更多
太酷不给撩
4楼-- · 2019-01-18 14:35

check out Eclipse, it has an embedded browser which is configurable by the user (they support multiple browsers).

you can probably embed their browser even if you use an AWT based application using the AWT_SWT bridge.

this article may help you get started.

查看更多
贼婆χ
5楼-- · 2019-01-18 14:36

Lobo is a Java web browser which can be embedded into Swing applications.

It supports HTML 4, CSS 2, and Javascript, which is more up-to-date compared to the JEditorPane which only supports HTML 3.2.

For some ideas on what is possible, the Lobo Browser API documentation should provide an idea of what is possible to do with Lobo. In particular, the org.lobobrowser.gui has a BrowserPanel class which is a subclass of JPanel, so it can be directly embedded in Swing applications.

For example, the BrowserPanel.navigate method can be used to jump to web pages, and there are many Listeners which can capture events which occur in the browser.

查看更多
SAY GOODBYE
6楼-- · 2019-01-18 14:53

You could try JxBrowser library: http://www.teamdev.com/jxbrowser/features/

For example to embed Mozilla browser into your Java Swing application you just need to do the following code:

Browser browser = BrowserFactory.createBrowser(BrowserType.Mozilla);

JFrame frame = new JFrame();

frame.add(browser.getComponent(), BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

browser.navigate("http://www.google.com");
查看更多
神经病院院长
7楼-- · 2019-01-18 14:54

You could also try the JWebBrowser from DJ Native Swing: http://djproject.sourceforge.net/ns

查看更多
登录 后发表回答