【问题标题】:How to append a string in java swing JTextPane?java - 如何在java swing JTextPane中附加一个字符串?
【发布时间】:2013-03-11 12:03:02
【问题描述】:

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

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

【问题讨论】:

标签: java swing jtextpane styleddocument


【解决方案1】:

发现另一个类似的问题,其答案使用了StyledDocument,并在StyledDocument 的实例上调用insertString() 方法将文本附加到它,然后将StyledDocument 写回JTextPaneJTextPane appending a new string

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 2012-10-21
    • 1970-01-01
    • 2013-04-05
    • 2013-07-20
    • 2018-05-25
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    相关资源
    最近更新 更多