Re: How to know when does a JTree become visible/invisible?



You say you have tabs. I assume you are using a JTabbedPane. I would
make the content in each of the tabs its own class that implements an
interface.

public interface TreeWidget {
public void loadTree(Object parameter);
}

public class TabPanelA implements TreeWidget {
JTree tvwTreeA = new JTree(new DefaultTreeModel(new
DefaultMutableTreeNode("Root")));
... // other stuff here
public void loadTree(Object parameter) {
... // stuff here to load tree
}
}

public class MyFrame extends JFrame {
JButton cmdLoad = new JButton("Load");
JTabbedPane tabbedPane = new JTabbedPane();

public MyFrame() {
this.setSize(800, 600);
this.setVisible(true);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(cmdLoad, BorderLayout.NORTH);
this.getContentPane().add(tabbedPane, BorderLayout.CENTER);
tabbedPane.addTab("Panel A", new TabPanelA());
cmdLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object parameter = ...// parameter to pass to the tree

((TreeWidget)tabbedPane.getSelectedComponent()).loadTree(parameter);
}
});
}

.