i will tell you the idea how i implemented this and also how it is implemented in Eclipse (LineNumber track consists of JPanel and JLabels with numbers):
1.create private class which implements DocumentListener and it extends Thread.
private class MyDocumentListener extends Thread implements DocumentListener {
public void changedUpdate(DocumentEvent e) {
//Plain text components do not fire these events
}
public void insertUpdate(DocumentEvent e) {
Document doc = (Document)e.getDocument();
2.then you should know every time when you type the rows size of the JTextArea,remember everything in this class(supposing that your JTextArea is tdefined as textArea):
int rows=textArea.getLineCount();
3.removes evertyhing from your LineNumbers panel (supposing that LineNumber track is JPanel lineNumberPanel):
lineNumberPanel.removeAll();
4.Add again labels on the line number count panel and repaint it:
for(int i=1;i<=rows;i++){
JLabel lineCount=new JLabel(""+i);
lineCount.setFont(textArea.getFont());
lineNumberPanel.add(lineCount);
}
lineNumberPanel.updateUI();
}
5.the same you can do when you remove the line:
public void removeUpdate(DocumentEvent e) {}
I hope you understood.Welcome