Removing lines of text from a JTextArea
843805Dec 6 2005 — edited Feb 16 2007I am appending lines to a JTextArea, once the line count hits 1000 I need to commence removing them from the top of the JTextArea to maintain it at 1000 line as they are no longer required. Currently I am using the following logic; but it seems a bit of a messy way to acheive this. Is there a cleaner way. ( I have tried setRows() )
logArea.append(logFile.datestamp() + " " + str + "\n");
if (logArea.getLineCount() > SCREEN_LINES) {
try {
logArea.select(logArea.getLineStartOffset(0), logArea.getLineEndOffset(0));
logArea.replaceSelection(null);
}
catch (BadLocationException e) {
}
}