Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

  • 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?
like image 587
MWeller Avatar asked Nov 23 '25 14:11

MWeller


1 Answers

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"));
like image 152
Ernest Friedman-Hill Avatar answered Nov 26 '25 03:11

Ernest Friedman-Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!