Is there a way to add a css file to jEditorPane?

A fairly simple question: I have a line containing HTML that is passed to JEditorPane for consumption by the user.

Can I attach a CSS file (or a line containing CSS rules) to provide a more specific text style?

+4
source share
2 answers

HTMLEditorKit is looking for default.css file by default - I'm not sure where.

Alternatively, this should work:

 StyleSheet ss = new StyleSheet(); ss.importStyleSheet(styleSheetURL); HTMLEditorKit kit = (HTMLEditorKit)jEditorPane.getEditorKit(); kit.setStyleSheet(ss); 

However, note that HTMLEditorKit only supports a limited subset of CSS 1.

+4
source

Can't you add a style tag along with the HTML content in setText() ?

eg.

 jEditorPane.setText( "<html><head><style type=\"text/css\">...</style></head><body>..."); 
+2
source

All Articles