Displaying XHTML in Swing (JEditorPane)

I am writing a GUI Java application using Swing. One of the GUI components is the JEditorPane, which renders HTML. All rendering is fine except that it shows the XML header on the first line:

?xml version="1.0" encoding="UTF-8" standalone="no"?>

I did a little googling and I found the same question here and there, but never any answer. I know that using some other projects like "Flying saucer" is an option, but before I start adding other libraries to my project, is there a way to make it work with Swing?

Two notes:

  • I can replace the JEditorPane with another component if it can help. I don't use it for any other functionality other than HTML rendering.
  • I am currently using a workaround for this, which works great, but I have the feeling this is an ugly hack:
    html = html.replaceFirst("\\<\\?.*\\?\\>", "");


+2


source to share


1 answer


The Flying Saucer is a good choice for XHTML. The JEditorPane cannot even handle self-closing tags, and there are no other components that come with a standard JDK that you can use.



+2


source







All Articles