I have seen many questions here about displaying HTML content in a swing application. But none of the libraries support html5(I cant afford JxBrowser).
I have some locally stored html5 webpages and i want to show them in my swing application. One idea is embedding firefox or chrome into my java application and removing the controls.
How can I display html5 content in my swing application?
To specify that a component's text has HTML formatting, just put the <html> tag at the beginning of the text, then use any valid HTML in the remainder. Here is an example of using HTML in a button's text: button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>"); Here is the resulting button.
Swing in Java is a lightweight GUI toolkit which has a wide variety of widgets for building optimized window based applications. It is a part of the JFC( Java Foundation Classes). It is build on top of the AWT API and entirely written in java. It is platform independent unlike AWT and has lightweight components.
Nowadays, the best way to add Java to HTML is through the so-called JavaServer Pages (JSPs). A JSP page is a file with the extension . jsp. It is an HTML markup containing several JSP tags.
You should look into new JavaFX browser that fully supports HTML5 and written in pure Java. You can easily integrate it into any Swing application - see the official description: http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm
But i guess it might force you to use JDK7+ to fully support various OS.
Sorry to necro this old thread. But, this is still a very relevant question today, so I'd thought I'd chime in with extra information and options.
Agree with the comments above about WebKit. It's built into Java, it's fast, and it's free, and it is so easy to use. Oracle's tutorials / examples on this are some of the best and clearest I've seen on their web site (you will be up and running with a basic Java web page display app very quickly): https://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm
There is really only 1 restriction / limitation with WebKit: it is JavaFX, you cannot embed it directly into Swing or AWT controls. However, you can embed the JavaFX scene in a Swing JPanel (or other container) so your Swing App can show the HTML5.
And, with Oracle now "decoupling JavaFX" (and therefore WebKit) from the main JDK / JRE, this might add extra steps to people wanting to use your Java App. e.g. they might need to download and install JavaFX for their platform separately (it it exists).
Ref: Java SE 11: The Great Removal, https://www.reddit.com/r/programming/comments/9nakq3/java_se_11_the_great_removal/
Or you could use something like GraalVM (or some other packager) to build a stand alone application and distribute that.
Ref: Ten Things You Can Do With GraalVM - Oleg Šelajev, https://www.youtube.com/watch?v=tEaEAq0L9Pk
Anyway, hope this helps someone. :)
WebKit is integrated in Java 8, so you don't need to jump through hoops. It is continuously update. It is available as the JavaFX WebView control. Java also comes with the Nashorn javascript engine that can call Java from JavaScript. Overall performance is excellent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With