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

后端 未结 2 1192
小蘑菇
小蘑菇 2021-01-18 10:28

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

2条回答
  •  耶瑟儿~
    2021-01-18 10:58

    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.

提交回复
热议问题