31

I'd like to have Gecko, WebKit, or another webbrowser embedded in Java as a Swing/AWT control. I'm looking for something different than JRex or JWebPane.

spongebob
  • 8,370
  • 15
  • 50
  • 83
  • It sure is a pity JwebPane hasn't seen the light of day. http://groups.google.com/group/javaposse/browse_thread/thread/5e9d30b484e084b4 may be of interest. – JasonPlutext Nov 15 '10 at 01:59

3 Answers3

15

You could use JxBrowser. It features a Swing/JavaFX component that wraps the Chromium engine while providing a rich API and out-of-the-box hardware-acceleration through the GPU.

Unfortunately, they've dropped support for other engines (like Gecko and WebKit) since 4.0 version.
Note that it's not free, except for open-source projects.

spongebob
  • 8,370
  • 15
  • 50
  • 83
Alexis Dufrenoy
  • 11,784
  • 12
  • 82
  • 124
  • It's used by Selenium, for example – Alexis Dufrenoy Nov 14 '10 at 13:40
  • 10
    All JXBrowser free for open source information seems to have been removed from their website. Does anyone know if it is still free for open source? AS @Supuhstar said, it is quite an expensive product. They can charge whatever they want for it, but very few open source projects can afford to pay $4,600 for a project license (And the per-developer price of $1,600 doesn't make any sense for open source, plus it's also too expensive for open source projects). Unfortunately, this seems to be the only java component which is ready for serious, browser-based applications. – Matt Eskridge Aug 23 '14 at 22:09
  • JxBrowser is absolutely free for Open-Source and Academic projects. You just need to select appropriate options when requesting evaluation license: https://www.teamdev.com/jxbrowser#evaluate – Vladimir Sep 12 '16 at 19:37
14

JCEF

JCEF (Java Wrapper for the Chromium Embedded Framework) is a Java wrapper around CEF, which is in turn a wrapper around Chrome:

Both projects seem quite active and the browser rendering is much faster than JavaFX's WebView (at least with JDK 8u20).

JFXPanel

It is also possible to use the JavaFX WebView in a Swing application via the JFXPanel.

public class JavaFxWebBrowser extends JFXPanel {
    private WebView webView;
    private WebEngine webEngine;

    public JavaFxWebBrowser() {
        Platform.runLater(() -> {
            initialiseJavaFXScene();
        });
    }

    private void initialiseJavaFXScene() {
        webView = new WebView();
        webEngine = webView.getEngine();
        webEngine.load("http://stackoverflow.com");

        Scene scene = new Scene(webView);
        setScene(scene);
    }
}
Community
  • 1
  • 1
Luke Quinane
  • 16,447
  • 13
  • 69
  • 88
13

If SWT is an option, you can use the SWT Browser widget, this will use a platform-specific browser (e.g. Mozilla, Webkit, IE) to actually display the content. Have a look at this Eclipse article for an overview.

If you don't want to use SWT, then I recommend JavaXPCOM. This allows you to embed Gecko in a Java application.

Grodriguez
  • 21,501
  • 10
  • 63
  • 107