I'm using JTextPane to log some data from a network application and after the program runs for about more than 10 hours or so I get memory heap error. Text continues to get added to the JTextPane which keeps increasing memory usage. Is there anyway I can make the JTextPane act like a command prompt window? Should I get rid of the old text as new text comes in? This is the method I'm using to write to the 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);
}