views:

1183

answers:

4

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

A: 

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

kgiannakakis
+2  A: 

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:

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

JuanZe
The SO link suggests JWebPane, but you suggest JEditor. I do not think they are the same thing. Thanks for the links, I will investigate both.
jrhicks
+2  A: 

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.

Omry
Is there a stand alone version of this?
Thorbjørn Ravn Andersen
A: 

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.

coobird