JTextPaneを使用してネットワークアプリケーションからのデータをログに記録していますが、プログラムを約10時間以上実行すると、メモリヒープエラーが発生します。テキストは引き続きJTextPaneに追加され、メモリ使用量が増加し続けます。とにかく、JTextPaneをコマンドプロンプトウィンドウのように動作させることはできますか?新しいテキストが入ってくるので、古いテキストを取り除く必要がありますか?これは、JTextPaneへの書き込みに使用しているメソッドです。
volatile JTextPane textPane = new JTextPane();
public void println(String str, Color color) throws Exception
{
str = str + "\n";
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("I'm a Style", null);
StyleConstants.setForeground(style, color);
doc.insertString(doc.getLength(), str, style);
}