i am writting an application package contains a main class where is the main method and which is seperated from the GUI class, and the GUI class contains a jframe with a jtabbedpane that have two tabs, first tab contains a jtable, call it jtable1, second tab contains 3 tables, call them jtable2, jtable3, and jtable4, i have added in the GUI class constructor which is being called in the new instance in the main class, i have added in this GUI class constructor a ListSelectionListener to the first jtable :
jTable1.getSelectionModel().addListSelectionListener((ListSelectionEvent event) -> { // do some actions here, for example /* my code */ });
and by good destinies, it is working very well, to such selection, and i have also added ChangeListener to the jtabbedpane in the GUI class constructor that is working also very well :
jTabbedPane1.addChangeListener((ChangeEvent e) -> {
/* my code */
});
but when i tried to begin adding a ListSelectionListener in the GUI class constructor to the first table, which we called jtable2, in the second tab which contains three tables and would add ListSelectionListener to them, it doesn't respond to any selection, and the code of adding ListSelectionListener to jtable2 was :
jTable2.getSelectionModel().addListSelectionListener((ListSelectionEvent event) -> { System.out.println("jTable2 Selected"); /* mycode */ });
Undoubtedly the question is what is the problem and how to solve it? but if it is not simple, what are probabilities or how can i explain more?
Note : the adding of ListSelectionListener would be done to the other tables in the second tab (jtable3, and jtable4), and it would be added by willing to other planned tabs that would be created and contain tables
Thanks for Looking and Caring
The problem was in re-creating the not listened action's jtable in it's jTabbedPane changes, as in each tab change, i was re-creating jtable to update it with the new entered informations in the jtables of the other tabs :
So, the problem was in re-creating the jtable so the listened and the observed jtable object in the memory is missed from pointing and listening, therefore the solution is to update the model of the jtable without creating new jtable object and then set it to the jtable: