渲染 HTML 以在 Java 应用程序中显示

发布于 2024-11-18 19:08:45 字数 1436 浏览 10 评论 0原文

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

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

发布评论

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

评论(2

深陷 2024-11-25 19:08:45

Swing HTML 支持

Swing 组件(1) 将呈现 HTML 3.2 和基本样式。如果您控制 HTML,这可能是一个可行的选择。

HTML

请参阅我的回答此处,了解 2 个快速示例 的 HTML 图像

直接使用 Jar 文件中

JEditorPane 显示 Jar'd HTML

使用相对引用

Image referenced from base

CSS

有关使用 CSS 在 Swing 组件中设置 HTML 样式的示例,请参阅以下问题的答案:

Java:HTML Swing,链接边距不起作用

Link Cloud

JButtons 中的自动换行

自动换行 @ 160px自动换行@ 200px

警告

  1. 更具体地说,一些 Swing 组件支持 HTML。第一个屏幕截图来自 JEditorPane,其余的使用 JLabel。许多组件使用 JLabel 作为默认渲染组件,例如工具提示、&标签。默认列表&表格渲染器。 JButton 部分支持 HTML。对于禁用的按钮,它将错误地呈现。 JTextPane(样式文本)也支持 HTML,但 JTextArea & JTextField(纯文本)不需要。

另请参阅

有关详细信息,请参阅如何在 Swing 组件中使用 HTML 在 Java 教程中。

Swing HTML support

Swing components(1) will render HTML 3.2 and basic styles. It might be a viable option if you control the HTML.

HTML

See my answer here for 2 quick examples of using images in HTML

Direct from a Jar file

JEditorPane displaying Jar'd HTML

Using relative references

Image referenced from base

CSS

For examples of styling HTML in Swing components using CSS, see the answers to:

Java: HTML in Swing, link margin not working

Link Cloud

Word Wrap in JButtons

Word wrap @ 160pxWord wrap @ 200px

Caveat

  1. More specifically, some Swing components support HTML. The 1st screen shot is from a JEditorPane, the rest use a JLabel. Many components use a JLabel as the default rendering component, such as tool tips, & default list & table renderers. JButton supports HTML partly. It will render incorrectly for a disabled button. JTextPane (styled text) also supports HTML, but JTextArea & JTextField (plain text) do not.

See Also

For more information see How to Use HTML in Swing Components in the Java Tutorial.

我早已燃尽 2024-11-25 19:08:45

Native Swing 允许在 Java Swing 应用程序中使用 SWT 浏览器并将其与 Swing 小部件混合。它支持多个平台上的 WebKit 和 Xulrunner(以及 Windows 上的 IE)。确保拥有与最新 SWT 实现兼容的 libwebkit 或 libxulrunner,如 SWT 中所述常见问题解答
要使用的浏览器引擎由传递给 JWebBrowser 的 NSOption 控制:

JWebBrowser geckoWebView = new JWebBrowser(JWebBrowser.useXULRunnerRuntime());
JWebBrowser webkitWebView = new JWebBrowser(JWebBrowser.useWebkitRuntime());

Native Swing allows to use an SWT Browser in Java Swing applications and to mix it with Swing widgets. It supports both WebKit and Xulrunner on several platforms (as well as IE on Windows). Make sure to have a libwebkit or libxulrunner that is compatible with the latest SWT implementation as described in the SWT FAQ
The browser engine to use is controlled by an NSOption passed to JWebBrowser:

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