How do I format my HTML correctly with an external CSS file?
2 answers
Based on JavaDoc - jEditorPane supports HTML 3.2 and CSS1 blood edge so the short answer is you really don't want to try to render modern web pages with it.
However, you can do this:
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
URL url = new URL(location of your stylesheet);
StyleSheet styleSheet = new StyleSheet();
styleSheet.importStyleSheet(url)
kit.setStyleSheet(styleSheet);
+3
source to share
I don't think you can render modern HTML with JEditorPane
. From the docs :
The following content types are known by default:
...
Text / HTML
HTML text. The collection used in this case is the class
javax.swing.text.html.HTMLEditorKit
that provides HTML 3.2 support.
HTML 3.2 as defined in the last century, i.e. without CSS / CSS2.
You can use an external HTML rendering library as we know it now. A bit of work on Google there will appear several options, or you can look here .
+1
source to share