I am creating a kind of notepad who have a pane for line counter who tell me the position of line (it increments when I press Enter) and another pane for line and column counter (just like Notepad++ have). I wanted to add tabs, dynamically, so everytime I select "New" option, a new tab will be created. By default, my notepad starts with one tab opened, just like Notepad++ does. Lets call this tab, TAB1
if(menuFileNew == e.getSource())
Action newline = new AbstractAction()
public void actionPerformed(ActionEvent e)
You "new line" Action is incorrect. You are hardcoding the text area variable you want to change.
Action should extend
TextAction (not AbstractAction). Then you can use the
getFocusedComponent() method of the
TextAction to get the text area that currently has focus.
For a simple example check out: Clear current FocusOwner (jTextfield)
Also, that is not the way to add a new line character to a text field. Don't use the setText() method. Instead you should be using the
Although the real question is why are you creating this Action? Adding a newline to the text area is the default behaviour when you press the Enter key.