0

在用于格式化的 JEditorPane 中,我使用的是 Courier New 字体类型。但是,由于 HTML 对空格不敏感,因此正在删除空格。因此,如果我尝试打印这样的内容:“1 3 4”,它会删除多余的空格并在实践中打印“1 3 4”。有什么想法吗?

  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; }");
4

1 回答 1

1

我得到了答案:

sString=sString.replaceAll(" ", " ");
于 2012-09-12T23:57:06.257 回答