Embedding Gecko/WebKit in Java

℡╲_俬逩灬. 提交于 2019-12-27 20:20:08

问题


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.


回答1:


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.




回答2:


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.




回答3:


JCEF

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

  • https://bitbucket.org/chromiumembedded/java-cef
  • https://bitbucket.org/chromiumembedded/cef

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


来源:https://stackoverflow.com/questions/2653949/embedding-gecko-webkit-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!