Java/Swing でチャット プログラムを作成しており、テキストは Jtextpane オブジェクトでレンダリングされます。現在、既存の文書に追加する方法がわからなかったため、新しいメッセージによって古いメッセージが消去されます。これを行う方法?
public void addMessage(String sender, String msg) throws BadLocationException, IOException{
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = new HTMLDocument();
pane.setEditorKit(kit);
pane.setDocument(doc);
kit.insertHTML(doc, doc.getLength(), "<b>[" + sender + "]</b> " + msg, 0, 0, null);
}