Skip to main content

refering to a jtable from another 'brother' component

No replies
Joined: 2007-12-13
Points: 0

Hi, I've got a little problem, maybe is something silly, but the fact is that maybe I don't understand the logic of the swing containers at all....

The problem is the next:
I've got a container with two components wich are two jbuttons.
The first one, as a result of pressing it, creates a new jtable inside a scrollpanel:
final JTable table = new JTable(dtm);
JScrollPane scrollPane = new JScrollPane(table);
after it, it is added to the main content pane..

jContentPane.add(scrollPane, null);

in the other hand in the code of the other independent button 'pressed event', I try to make a call to a method of the jtable created.... but it isn't possible to do that call... I supose it is related with the fact that the jtable is just created when you press the first button... An obvious solution would be to use a global variable, but it's not very elegant...

How to refer to that table from the code of the second button? how could I make it accesible from it, (making the second button to be inside de table wouldn't be a solution for me).

Thank you!!!! I'm just an iniciated so all of your advices are gold for me!