简体   繁体   English

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

[英]Show HTML mark-up in JFrame or open Browser

I am writing a Java program that creates HTML code. 我正在编写一个创建HTML代码的Java程序。

What's the best/easiest possibility to have a preview of the code? 预览代码的最佳/最简单的可能性是什么?

  • Show the code in the JFrame : How can I do this? JFrame显示代码:我该怎么做?
  • Open the windows browser with the created File? 用创建的文件打开Windows浏览器? Is this possible? 这可能吗?
  • A totally different approach? 一种完全不同的方法?

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: 以下是Java教程中的一个页面,其中显示了如何在Swing中显示HTML(您使用file: URL来显示文件的内容。)您可以使用Java 6的Desktop类在外部浏览器中显示URL:

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

Alternately, save the data in a file with the *.html extension and use 或者,将数据保存在扩展名为*.html的文件中并使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM