Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Removing lines of text from a JTextArea

843805Dec 6 2005 — edited Feb 16 2007
I 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) {
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2007
Added on Dec 6 2005
6 comments
2,564 views