在 Swing 中显示 XHTML (JEditorPane)

发布于 2024-08-03 22:56:03 字数 506 浏览 2 评论 0原文

我正在使用 Swing 编写带有 GUI 的 Java 应用程序。 GUI 组件之一是呈现 HTML 的 JEditorPane。所有渲染都很好,除了在第一行显示 XML 标头:

?xml version="1.0"encoding="UTF-8"standalone="no"?>

我用 google 搜索过一点点,我到处都发现了同样的问题,但从来没有任何答案。我知道使用“飞碟”等其他一些项目是一种选择,但在我开始向我的项目添加其他库之前 - 有没有办法让它与 Swing 一起工作?

两个注意事项:

  • 如果有帮助的话,我可以用其他一些组件替换 JEditorPane。除了 HTML 渲染之外,我没有将它用于任何其他功能。
  • 我目前正在使用一种解决方法,效果很好,但我感觉这是一个丑陋的黑客:
    html = html.replaceFirst("\\<\\?.*\\? \\>", "");

I'm writing a Java application with GUI using Swing. One of the GUI components is a JEditorPane that renders HTML. All the rendering is fine except that it shows in the first line the XML header:

?xml version="1.0" encoding="UTF-8" standalone="no"?>

I've googled a little bit and I've found the same question here and there, but never any answer. I know that using some other projects like "Flying saucer" is an option, but before I start adding other libs to my project - is there a way to make it work with Swing?

Two notes:

  • I can replace JEditorPane with some other component if it can help. I'm not using it for any other features than HTML rendering.
  • I'm currently using a workaround for that, which works fine, but I have a feeling this is an ugly hack:
    html = html.replaceFirst("\\<\\?.*\\?\\>", "");

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

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

发布评论

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

评论(1

偏爱你一生 2024-08-10 22:56:03

Flying Saucer 是 XHTML 的一个不错的选择。 JEdi​​torPane 甚至无法处理自关闭标签,并且标准 JDK 中没有其他可供您使用的组件。

Flying Saucer is a good choice for XHTML. JEditorPane can't even handle self closing tags and there are no other components that come with the standard JDK that you can use.

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