问题描述
我有JFrame Main,它包含左侧JXTaskPainContainer(内容菜单)和右侧cardLayout面板。内容菜单有一个JButton btn(数据),当我们点击btn它显示在cardLayout面板上时 - > JPanel测试。在内容菜单下有addButton,它添加动态btn - > data2,data3,....这里给出的主框架布局:
I have JFrame Main which contains in left side JXTaskPainContainer (content menu) and right side cardLayout panel. Content menu has a JButton btn("data"), when we click btn it shows on cardLayout panel -> JPanel Test. Under content menu there is addButton, which adds dynamic btn -> "data2", "data3",.... The layout of Main frame given here:
Main frame
| jButton2 |
-------------
|Content menu| CardLayout Panel
|---------- |------------------------------------|
| //shows | |
|data1 ------|-> Test jPanel [Test.add(jButton1)] |
|data2 ------|-> Test jPanel [same as above ] |
|data3 ------|-> Test jPanel [same as above ] |
| ... | |
|---------- |------------------------------------|
| AddButton | |
//data2, data3 dynamically added by AddButton
我尝试过:
jButton2必须调用Test.jButton1:
What I have tried:
jButton2 must call Test.jButton1:
private void jButton2actionPerformed(java.awt.event.ActionEvent evt) {
Test.jButton1.doClick(); //here I want to call all jButton1 (i.e. data2, data3,...)
}
但是当我点击jButton2时,它只调用最后点击的Test.jButton1。例如,如果我添加了动态data2和data3,那么只点击了data3的jButton1,因为data2没有任何意义。
我想问一下如何调用所有的Test.jButton1动作命令在Main类中动态添加data2,data3,...?
but when I click jButton2 it calls only last clicked Test.jButton1. For example, if I added dynamic data2 and data3, then only jButton1 of data3 is clicked, for data2 is no sense.
I would like to ask how can I call all the Test.jButton1 action commands of dynamically added data2, data3,... in Main class?
推荐答案
这篇关于获取动态添加的jbutton动作命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!