如何在 Java Swing 中的 JPanel 内呈现基本 HTML 标记?

发布于 2024-11-15 20:28:24 字数 246 浏览 4 评论 0原文

我想做一些非常简单的事情,如下所示:

JPanel htmlPanel = new HtmlPanel("<html><body><h1>hello world</h1></body></html>");

我想我在某处看到过正是这样做的代码。 CSS 和 JS 怎么样? JPanel 可以轻松支持这一点吗?是否有图书馆可以满足我的要求?

I want to do something really simple like this:

JPanel htmlPanel = new HtmlPanel("<html><body><h1>hello world</h1></body></html>");

I think I had seen code somewhere that did exactly this. What about CSS and JS? Can the JPanel be made to support this easily? Are there libraries somewhere that do what I am asking for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自由如风 2024-11-22 20:28:24

检查此处了解如何向 JEditorPane 添加 CSS 支持。您将需要一个 HTMLEditorKit

我不明白为什么 JEditorPane 需要 JavaScript 支持。它的基本用途是呈现用 HTML 和 CSS 编写的帮助页面。

如果您需要将真正的 McCoy 嵌入到您的应用程序中,请尝试 Lobo Java Web 浏览器。 Lobo 执行 JavaScript 和 CSS,并且 100% 开源 Java。

2015 年 11 月:Lobo 浏览器的最新分支是 Lobo Evolution

Check here to see how to add CSS support to your JEditorPane. You will need an HTMLEditorKit.

I do not see why you would need JavaScript support for a JEditorPane. The basic use of it is to render Help pages written in HTML and CSS.

If you need to have the real McCoy embedded into your application, try the Lobo Java Web Browser. Lobo does JavaScript and CSS and is open source 100% Java.

November 2015: The latest fork of the Lobo Browser is Lobo Evolution.

牵强ㄟ 2024-11-22 20:28:24

听起来您正在考虑 JEditorPane。它可以显示来自 URL 等的 html。
Swing 教程,编辑器窗格。

对 JavaScript 的支持不存在。

您可以尝试第三方组件,例如 flying-saucer,它是一个 XML/纯 Java 中的 XHTML 和 CSS 2.1 渲染器。

Sounds like you were thinking of the JEditorPane. It can display html from e.g. an URL.
Swing tutorial, Editor panes.

The support for javascript is nonexistent.

You can try out third party components such as flying-saucer, which is a XML/XHTML and CSS 2.1 renderer in pure Java.

自我难过 2024-11-22 20:28:24

如果有人仍在寻找简单的解决方案来启用 HTML 标记的显示:使用 JLabel 并将文本括在“”中和“” (不需要正文标签)。

查看如何在 Swing 组件中使用 HTML。我在寻找一种在表格中显示数据的简单方法时刚刚遇到了这个,它就像一个魅力。

In case anyone is still looking for an easy solution to just enable display of HTML-Markup: Use a JLabel and enclose the text in '<html>' and '</html>' (body tag isn't needed).

Have a look at How to Use HTML in Swing Components. I just came across this when looking for an easy way to display data in tables, and it works like a charm.

少跟Wǒ拽 2024-11-22 20:28:24

JWebPane,一个基于 WebKit 的 Java 组件,但该项目似乎已经消亡了很久以前和/或刚刚安静下来。有些人仍然希望它能够发布,我知道的另一个是 WebKit for SWT,但它似乎仅适用于 Win32。 :(

There was JWebPane, a Java component based on WebKit, but that project seems to have died a long time ago and/or has just gone quiet. Some people are still hoping it will be released, The other one I know of is WebKit for SWT, but it appears to be for Win32 only. :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文