我有一个基于 HTML 的 jEditorPane。我发现你可以使用:
String text = jEditorPane1.getDocument().getText(0, jEditorPane1.getDocument().getLength());
text = text.replaceAll("(?<!^)\n", "\n<br />");
jEditorPane1.setText("<html>" + text + "</html>");
通过这种方式,我从编辑器窗格中获取了文本。当我想把它放回编辑器窗格时,我只需用 < br /> 替换换行符。然后把它放回去。
直到现在一切都很好。但是当我第二次从编辑器窗格中获取文本时,没有换行符。
我怎样才能保留这个换行符?