-1

I have a desktop program with 3 tabs i'm building in netbeans. There is 1 text input field below the three tabs. each tab has a jtextarea component. When i type in the text input field and hit enter i want it to add that text to the textarea contained by the currently selected tab.

I've been playing around with

jTabbedPane1.getSelectedIndex()

jTabbedPane1.getTabComponentAt()

How can i use the index to reference it back to the textarea associated with that tab?

Big java noob here.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
stihl
  • 241
  • 2
  • 6
  • 16

1 Answers1

2

The simplest way would be to use an array of JTextArea components corresponding to the order that they appear on the JTabbedPane.

JTextArea[] textArea = new JTextArea[3];
// assign textAreas... 

You could then set the text using the appropriate index:

int index = jTabbedPane1.getSelectedIndex();
textArea[index].setText(myField.getText());
Reimeus
  • 158,255
  • 15
  • 216
  • 276