在 Java 中嵌入 Gecko/WebKit
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2653949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embedding Gecko/WebKit in Java
提问by
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
.
我希望将 Gecko、WebKit 或其他 Web 浏览器作为 Swing/AWT 控件嵌入 Java 中。我正在寻找与 JRex 或JWebPane
.
回答by Alexis Dufrenoy
You could use JxBrowser. It features a Swing/JavaFX component that wraps the Chromiumengine while providing a rich API and out-of-the-box hardware-acceleration through the GPU.
您可以使用JxBrowser。它具有一个 Swing/JavaFX 组件,该组件包装Chromium引擎,同时通过 GPU 提供丰富的 API 和开箱即用的硬件加速。
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.
不幸的是,自 4.0 版本以来,他们已经放弃了对其他引擎(如 Gecko 和 WebKit)的支持。
请注意,它不是免费的,开源项目除外。
回答by Grodriguez
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 articlefor an overview.
如果 SWT 是一个选项,您可以使用SWT 浏览器小部件,这将使用特定于平台的浏览器(例如 Mozilla、Webkit、IE)来实际显示内容。查看这篇 Eclipse 文章以获取概述。
If you don't want to use SWT, then I recommend JavaXPCOM. This allows you to embed Gecko in a Java application.
如果您不想使用 SWT,那么我推荐JavaXPCOM。这允许您将 Gecko 嵌入到 Java 应用程序中。
回答by Luke Quinane
JCEF
联合基金
JCEF (Java Wrapper for the Chromium Embedded Framework)is a Java wrapper around CEF, which is in turn a wrapper around Chrome:
JCEF(Chromium Embedded Framework 的 Java Wrapper)是 CEF 的 Java 包装器,而 CEF 又是 Chrome 的包装器:
Both projects seem quite active and the browser rendering is much faster than JavaFX's WebView (at least with JDK 8u20).
这两个项目看起来都很活跃,浏览器渲染比 JavaFX 的 WebView 快得多(至少在 JDK 8u20 中)。
JFXPanel
JFX面板
It is also possible to use the JavaFX WebView in a Swing application via the JFXPanel.
也可以通过 JFXPanel 在 Swing 应用程序中使用 JavaFX WebView。
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);
}
}