java 在 Swing 中显示 HTML5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12698011/
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
display HTML5 in swing
提问by danrah
I have seen many questions here about displaying HTML content in a swing application. But none of the libraries support html5(I cant afford JxBrowser).
我在这里看到了很多关于在 Swing 应用程序中显示 HTML 内容的问题。但是没有一个库支持 html5(我买不起 JxBrowser)。
I have some locally stored html5 webpages and i want to show them in my swing application. One idea is embedding firefox or chrome into my java application and removing the controls.
我有一些本地存储的 html5 网页,我想在我的 Swing 应用程序中显示它们。一种想法是将 firefox 或 chrome 嵌入到我的 java 应用程序中并删除控件。
How can I display html5 content in my swing application?
如何在我的 Swing 应用程序中显示 html5 内容?
回答by Mikle Garin
You should look into new JavaFX browser that fully supports HTML5 and written in pure Java. You can easily integrate it into any Swing application - see the official description: http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm
您应该研究完全支持 HTML5 并用纯 Java 编写的新 JavaFX 浏览器。您可以轻松地将其集成到任何 Swing 应用程序中 - 请参阅官方说明:http: //docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm
But i guess it might force you to use JDK7+ to fully support various OS.
但我想这可能会迫使您使用 JDK7+ 来完全支持各种操作系统。
回答by Wheels Of Progress
Sorry to necro this old thread. But, this is still a very relevant question today, so I'd thought I'd chime in with extra information and options.
很抱歉要破坏这个旧线程。但是,今天这仍然是一个非常相关的问题,所以我想我会加入额外的信息和选项。
Agree with the comments above about WebKit. It's built into Java, it's fast, and it's free, and it is so easy to use. Oracle's tutorials / examples on this are some of the best and clearest I've seen on their web site (you will be up and running with a basic Java web page display app very quickly): https://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm
同意上面关于WebKit的评论。它内置于 Java 中,速度很快,而且是免费的,而且非常易于使用。Oracle 的教程/示例是我在他们的网站上看到的最好和最清晰的一些(您将很快启动并运行基本的 Java 网页显示应用程序):https: //docs.oracle.com/ javafx/2/webview/jfxpub-webview.htm
There is really only 1 restriction / limitation with WebKit: it is JavaFX, you cannot embed it directly into Swing or AWT controls. However, you can embed the JavaFX scene in a Swing JPanel (or other container) so your Swing App can show the HTML5.
WebKit 确实只有 1 个限制/限制:它是 JavaFX,您不能将它直接嵌入到 Swing 或 AWT 控件中。但是,您可以将 JavaFX 场景嵌入到 Swing JPanel(或其他容器)中,以便您的 Swing 应用程序可以显示 HTML5。
And, with Oracle now "decoupling JavaFX" (and therefore WebKit) from the main JDK / JRE, this might add extra steps to people wanting to use your Java App. e.g. they might need to download and install JavaFX for their platform separately (it it exists).
而且,随着 Oracle 现在从主 JDK/JRE 中“分离 JavaFX”(以及 WebKit),这可能会给想要使用您的 Java 应用程序的人增加额外的步骤。例如,他们可能需要为他们的平台单独下载和安装 JavaFX(它存在)。
Ref: Java SE 11: The Great Removal, https://www.reddit.com/r/programming/comments/9nakq3/java_se_11_the_great_removal/
参考:Java SE 11:大迁移, https : //www.reddit.com/r/programming/comments/9nakq3/java_se_11_the_great_removal/
Or you could use something like GraalVM (or some other packager) to build a stand alone application and distribute that.
或者你可以使用 GraalVM(或其他一些打包程序)之类的东西来构建一个独立的应用程序并分发它。
Ref: Ten Things You Can Do With GraalVM - Oleg ?elajev, https://www.youtube.com/watch?v=tEaEAq0L9Pk
参考:GraalVM 可以做的十件事 - Oleg ?elajev, https://www.youtube.com/watch ?v = tEaEAq0L9Pk
Anyway, hope this helps someone. :)
无论如何,希望这对某人有所帮助。:)
回答by Aleksandr Dubinsky
WebKit is integrated in Java 8, so you don't need to jump through hoops. It is continuously update. It is available as the JavaFX WebView control. Java also comes with the Nashorn javascript engine that can call Java from JavaScript. Overall performance is excellent.
WebKit 已集成在 Java 8 中,因此您无需跳槽。它是不断更新的。它可用作JavaFX WebView 控件。Java 还带有 Nashorn javascript 引擎,可以从 JavaScript 调用 Java。整体表现非常出色。