简体   繁体   中英

JEditorPane HTML rendering

I am using a JEditPane to render an HTML text that contains links, and make the links clickable. I have managed to do that but the text and the links are shown in an ugly font and color, the default blue underlined link, etc. Is there a way to change the default behavior of the JEditPane without editing the HTML inside?

Appreciate the help Thanks

Try adding a CSS style, like this:

JEditorPane jEditorPane = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("A {color:red}"); //change links to red
jEditorPane.setEditorKit(kit);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM