Skip to content Skip to sidebar Skip to footer

Is There A Way To Attatch A Css File To A Jeditorpane?

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

Solution 1:

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

Alternatively, this should work:

StyleSheetss=newStyleSheet();
ss.importStyleSheet(styleSheetURL);
HTMLEditorKitkit= (HTMLEditorKit)jEditorPane.getEditorKit();
kit.setStyleSheet(ss);

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

Solution 2:

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

e.g.

jEditorPane.setText( "<html><head><styletype=\"text/css\">...</style></head><body>...");

Post a Comment for "Is There A Way To Attatch A Css File To A Jeditorpane?"