Referencing

V

VD

Suppose I have defined separate classes by extending JFrame, JTable and and
JTree. I want to place the JTable and JTree in the JFrame. When someone
clicks on an item in the JTree I want the JTable to be updated with some
information based on the selection. What is the best way to do this?
Should a reference to the JFrame be passed to the constructors of JTable and
JTree when they are instantiated? Can a link be made between the JTree and
JTable without doing this?

Thanks.
 
A

ak

Suppose I have defined separate classes by extending JFrame, JTable and
and
JTree. I want to place the JTable and JTree in the JFrame. When someone
clicks on an item in the JTree I want the JTable to be updated with some
information based on the selection. What is the best way to do this?
Should a reference to the JFrame be passed to the constructors of JTable and
JTree when they are instantiated? Can a link be made between the JTree and
JTable without doing this?

something like this:

class MyFrame extends JFrame {

JTable table;
JTree tree;

public MyFrame() {
table = new ...;
tree = new ...;

tree.getSelectionModel().addTreeSelectionListener(new
TreeSelectionListener() {
//show data in JTable
});
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top