I'm interested in displaying HTML text (using CSS) in a Java app. What options do I have?
Although I don't use SWT in my app, I see SWT provides an interface to a WebKit browser on all platforms. Is there a way I can use SWT's WebKit integration to ask it to render the text in an image that I can reuse?
Swing components(1) will render HTML 3.2 and basic styles. It might be a viable option if you control the HTML.
See my answer here for 2 quick examples of using images in HTML
For examples of styling HTML in Swing components using CSS, see the answers to:
JButtons
JEditorPane
, the rest use a JLabel
. Many components use a JLabel
as the default rendering component, such as tool tips, & default list & table renderers. JButton
supports HTML partly. It will render incorrectly for a disabled button. JTextPane
(styled text) also supports HTML, but JTextArea
& JTextField
(plain text) do not.For more information see How to Use HTML in Swing Components in the Java Tutorial.