- You first need to decide what should trigger the line removal.
- Should it be the addition of a new line, so that total line number is constant. If so then you should write your code to call the line removal code in the same location that where a new line is added.
- Or should it be at a constant rate -- and if so, then you will want to use a Swing Timer for this.
- Then you need to decide which line to remove. If not the first line, then you'll need to figure out how to calculate which line. The
javax.swing.text.Utilities
class can help you find out the start and finish location of every line of text in your JTextArea.
Edit
You ask:
the main concern is about how to remove it from the JTextArea, i have already calculated the start and end positions of a line that has to be deleted.But what function can assist in removing just that one line?
- You would first get the JTextArea's Document by calling,
getDocument()
- Then you could call
remove(int offs, int length)
on the Document as per the Document API.