简体   繁体   中英

Adding text to jTextarea in jTabbedPane

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.

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM