1

我正在创建一个聊天应用程序。在这个聊天应用程序中,我必须使用 Java SwingJTextPane为一些特定的字符串赋予样式,例如用户的显示名称和消息的时间。这就是我选择JTextPaneover的原因JTextArea。在 JTextPane 中,我不能追加字符串,所以我创建了一个字符串缓冲区来追加字符串,然后我做jTextPane.setText(stringBuffer.toString()).

这是我的问题:当我将字符串附加到JTextPanevia aStringBuffer时,会有延迟。如何在 a 中逐行附加字符串JTextPane

4

1 回答 1

6

发现另一个类似的问题,其答案使用实例上的StyledDocumentand 调用方法将文本附加到它,然后写回:JTextPane appending a new stringinsertString()StyledDocumentStyledDocumentJTextPane

于 2012-06-28T12:54:21.000 回答