如何在 Java 应用程序中显示 html?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/817609/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:55:15  来源:igfitidea点击:

How to display html in a java application?

javahtmlbrowserjframe

提问by Aveen

Now I am working on implementing a browser in Java. I need to display the contents of a website (provided a url-address) inside a JFrame window. Is there a simple way of doing that?

现在我正致力于用 Java 实现浏览器。我需要在 JFrame 窗口中显示网站的内容(提供 url 地址)。有没有一种简单的方法可以做到这一点?

I tried JEditorPane, but it only supports HTML 3.2, so the contents of the website looks very weird.

我试过JEditorPane,但它只支持HTML 3.2,所以网站的内容看起来很奇怪。

Thanks

谢谢

回答by Oren Yosifon

I have good experience with: http://djproject.sourceforge.net/ns/

我有很好的经验:http: //djproject.sourceforge.net/ns/

Lets you cleanly embed a browser window within a Swing application, lets you manipulate the DOM and enables calling the host application from the browser itself.

允许您在 Swing 应用程序中干净地嵌入浏览器窗口,允许您操作 DOM 并允许从浏览器本身调用主机应用程序。

BR, Oren.

BR,奥伦。

回答by alphazero

Lobo is aiming for html 4 compliance.

Lobo 的目标是符合 html 4。

http://lobobrowser.org/java-browser.jsp

http://lobobrowser.org/java-browser.jsp

One could argue that the rendering aspect of a browser is one of the most, if not the most, challenging aspects of developing a browser. (Networking, thread management, security sandbox, etc. are all pretty much available out of the box on the JVM ...)

有人可能会争辩说,浏览器的渲染方面是开发浏览器中最具挑战性的方面之一。(网络、线程管理、安全沙箱等在 JVM 上几乎都是开箱即用的……)

So, if you're not up to writing your own components for dealing with correctly rendering documents based on xhtml, css, and javascript (not to mention various common plugins such as flash), then why not consider contributing to an open source effort such as lobo?

因此,如果您不能编写自己的组件来处理基于 xhtml、css 和 javascript(更不用说各种常见插件,例如 flash)的正确呈现文档,那么为什么不考虑为开源工作做出贡献,例如作为路博?

回答by m_vitaly

You should look at this question.

你应该看看这个问题

We use JDICand it runs very well on many platforms. The latest version was renamed and dropped many features (platform compatibility). But version 0.9.5, I think, works without problems.

我们使用JDIC,它在许多平台上运行良好。最新版本已重命名并删除了许多功能(平台兼容性)。但是我认为 0.9.5 版本可以正常工作。

Also there are plans for Web-kit based component integrated into swing. Don't remember the name of the project.

也有计划将基于 Web-kit 的组件集成到 Swing 中。不记得项目名称。

回答by Esko Luontola

I have seen IntelliJ IDEA to use an embedded version of Mozilla/Firefox for showing web pages inside the IDE, so that is one way of showing web pages inside a Java Swing application. I don't know whether it is simple or not, but at least the pages are rendered correctly. Google knows thisabout embed mozilla in java.

我已经看到 IntelliJ IDEA 使用 Mozilla/Firefox 的嵌入式版本在 IDE 中显示网页,因此这是在 Java Swing 应用程序中显示网页的一种方式。我不知道它是否简单,但至少页面呈现正确。谷歌知道大约在java中嵌入Mozilla浏览器

回答by thSoft

If you can use SWT, you could try the SWT browser widget: http://www.eclipse.org/articles/Article-SWT-browser-widget/browser.html.

如果您可以使用 SWT,您可以尝试使用 SWT 浏览器小部件:http: //www.eclipse.org/articles/Article-SWT-browser-widget/browser.html

If you have to stick to Swing, there is WebWindow, which is a bit outdated AFAIK.

如果你必须坚持使用 Swing,那就是 WebWindow,它有点过时 AFAIK。