views:

459

answers:

3

Simple enough question: I have a string containing HTML that is being handed off to a JEditorPane for user consumption.

Can I attach a CSS file (or string containing CSS rules) to allow for more specific styling of the text?

A: 

can't you just include a style tag along with the html content in setText()

ie

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

The HTMLEditorKit per default looks for a file default.css - I'm not sure where, though.

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.

Michael Borgwardt
A: 

Michael, Thanks for your link on limited subset

Syed Abdul Rahim