Reputation: 7458
In a JEditorPane for formatting purposes i am using Courier New font type. However the whitespaces are being removed as HTML is white-space insensitive. Therefore If I try to print something like this: "1 3 4", it removes the extra spaces and in practice prints "1 3 4". Any thoughts around this?
public JEditorPane editorPane;
editorPane.setEditable(false);
editorPane.setContentType("text/html");
// add a HTMLEditorKit to the editor pane
HTMLEditorKit kit = new HTMLEditorKit();
editorPane.setEditorKit(kit);
//...
//...
// add some styles to the html
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {color:#0f0; font-family:times; margin: 1px; }");
styleSheet.addRule("h1 {color:blue;}");
styleSheet.addRule("h2 {color:#ff0000;}");
styleSheet.addRule("."+StyleCourierNew+" {font-family:\"Courier New\"; font: 11px monaco; color: black; }");
Upvotes: 0
Views: 753