Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


What I have tried:

jButton2 must call Test.jButton1:

Java
private void jButton2actionPerformed(java.awt.event.ActionEvent evt) {
        Test.jButton1.doClick(); //here I want to call all jButton1 (i.e. 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?
Posted
Updated 16-Jul-16 23:17pm
Comments
Richard MacCutchan 16-Jul-16 5:35am    
You need to rethink your design, and create a method that performs all the necessary functions, independent of any user actions. You can then call that method from any of the click events as required.

1 solution

JButton button1 = new JButton("new button");
button1 .setActinCommand(idActin );
button1 .setActionListener(this);

...
void actionPerformed(ActionEvent e) {
String idActin = e.getActionCommand();
}

Try this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900