Embed browser in Java based desktop application [d

2019-01-18 14:05发布

问题:

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

回答1:

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.



回答2:

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



回答3:

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



回答4:

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.



回答5:

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



回答6:

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");