简体   繁体   English

在jTabbedPane中的jTextarea中添加文本

[英]Adding text to jTextarea in jTabbedPane

I have a desktop program with 3 tabs i'm building in netbeans. 我有一个在Netbeans中构建的带有3个选项卡的桌面程序。 There is 1 text input field below the three tabs. 三个选项卡下面有1个文本输入字段。 each tab has a jtextarea component. 每个选项卡都有一个jtextarea组件。 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. 当我在文本输入字段中键入内容并按Enter时,我希望它将该文本添加到当前所选选项卡包含的文本区域中。

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. Java大菜鸟在这里。

The simplest way would be to use an array of JTextArea components corresponding to the order that they appear on the JTabbedPane . 最简单的方法是使用一个JTextArea组件数组,该组件对应于它们在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());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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