Java 如何让JEditorpane保留空白

Java 如何让JEditorpane保留空白,java,swing,jeditorpane,Java,Swing,Jeditorpane,在一个用于格式化的窗格中,我使用了Courier的新字体类型。但是,由于HTML不区分空格,因此正在删除空格。因此,如果我尝试打印这样的内容:“1 3 4”,它会删除多余的空格,并在实践中打印“1 3 4”。有什么想法吗 public JEditorPane editorPane; editorPane.setEditable(false); editorPane.setContentType("text/html"); // add a HTMLEditorKit to t

在一个用于格式化的窗格中,我使用了Courier的新字体类型。但是,由于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; }");
我得到了答案:

sString=sString.replaceAll(" ", " ");

我得到了答案:st=st.replaceAll(“,”);