在 JFrame 或打开浏览器中显示 HTML 标记

发布于 2024-12-23 13:29:52 字数 178 浏览 2 评论 0原文

我正在编写一个创建 HTML 代码的 Java 程序。

预览代码的最佳/最简单的可能性是什么?

  • JFrame 中显示代码:我怎样才能做到这一点?
  • 使用创建的文件打开Windows浏览器?这可能吗?
  • 一种完全不同的方法?

I am writing a Java program that creates HTML code.

What's the best/easiest possibility to have a preview of the code?

  • Show the code in the JFrame: How can I do this?
  • Open the windows browser with the created File? Is this possible?
  • A totally different approach?

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

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

发布评论

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

评论(1

路弥 2024-12-30 13:29:52

两者都很容易做到。 这里是 Java 教程中的一个页面,展示了如何显示Swing 中的 HTML(您可以使用 file: URL 来显示文件的内容。)您可以使用 Java 6 的 Desktop 类在外部浏览器中显示 URL:

Desktop.getDesktop().browse(new URI("file://myfile.html"));

交替,将数据保存在扩展名为 *.html 的文件中并使用

Desktop.getDesktop().open(new File("myfile.html"));

Both are quite easy to do. Here is a page from the Java tutorial that shows how to display HTML in Swing (you'd use a file: URL to display the contents of a file.) You can display a URL in an external browser using Java 6's Desktop class:

Desktop.getDesktop().browse(new URI("file://myfile.html"));

Alternately, save the data in a file with the *.html extension and use

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