そこで、独自のテキストペインクラス(JTextPaneを拡張)を作成し、以下のメソッドを使用してテキストを追加しています。ただし、テキストを追加するには、ペインを編集可能にする必要がありますが、これにより、ユーザーはペインの内容を編集することもできます。
誰かが、ユーザーにそこにあるものを操作させずに、ペインにテキストを追加する方法を教えてもらえますか?
public void appendColor(Color c, String s) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
int len = getDocument().getLength();
setCaretPosition(len);
setCharacterAttributes(aset, false);
replaceSelection(s);
setCaretPosition(getDocument().getLength());
}