MWeller
MWeller

Reputation: 105

Show HTML mark-up in JFrame or open Browser

I am writing a Java program that creates HTML code.

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

Upvotes: 3

Views: 1728

Answers (1)

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

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"));

Upvotes: 4

Related Questions