它按照您的預期工作。
這裏是代碼。
doc.insertString(doc.getEndPosition().getOffset(), "test\n", null);
doc.insertString(doc.getEndPosition().getOffset(), "test\n", null);
doc.insertString(doc.getEndPosition().getOffset(), "test\n", null);
doc.insertString(doc.getEndPosition().getOffset(), "test\n", null);
的完整代碼。
jScrollPane1 = new javax.swing.JScrollPane();
jEditorPane1 = new javax.swing.JEditorPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setViewportView(jEditorPane1);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
pack();
- 檢查是否在編輯器窗格上設置了其他任何屬性。
- 您使用的是哪種編輯器套件?
- 嘗試打印輸入,並確保它與「\ n」
你也可以使用,
doc.insertString(doc.getLength(), "test\n", null);
你是如何從套接字的InputStream讀?使用BufferedReader.readLine()? 如果是這樣,讀取的行不會包含'\ n';你需要手動添加它。 – 2012-02-29 17:36:50
facepalm!我在我的一個方法中手動添加了'\ n',並且在另一個方法中忘記了它。這是第二個真正被召喚的人。哎呀! – James 2012-02-29 17:58:16