 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
lichuan.nj@gmail.com Guest
|
Posted: Fri May 11, 2007 2:42 pm Post subject: How to know when does a JTree become visible/invisible? |
|
|
Hello everyone, I would like to ask something.
I have few tabs, each contains a JTree in a JPanel to display a
(large) hierarchy. When I give the menu command to populate the trees
from an external file, I want only that tree in the currently visible
tab to be built. And when I switch to another tab later, it will does
the delayed instantiation.
The question is how can I get the visibility of a JTree contain in a
JPanel? isVisible, isShown on JTree seem not working. What is it the
semantics of isVisible, isShown for components in a tab? Yes I can
detect the visibility of the container JPanel insterd, but it breaks
in the boundary of several components in my program...
Thanks a lot in advance!
Chuan Li |
|
| Back to top |
|
 |
visionset Guest
|
Posted: Fri May 11, 2007 3:17 pm Post subject: Re: How to know when does a JTree become visible/invisible? |
|
|
<lichuan.nj (AT) gmail (DOT) com> wrote in message
news:1178876544.944041.88940 (AT) q75g2000hsh (DOT) googlegroups.com...
| Quote: | The question is how can I get the visibility of a JTree contain in a
JPanel?
|
Add a ComponentListener, implement the componentShown() method.
--
Mike W |
|
| Back to top |
|
 |
bcr666 Guest
|
Posted: Sat May 12, 2007 7:11 am Post subject: 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);
}
});
} |
|
| Back to top |
|
 |
lichuan.nj@gmail.com Guest
|
Posted: Sun May 13, 2007 8:02 pm Post subject: Re: How to know when does a JTree become visible/invisible? |
|
|
Thanks for your nice code bcr666, but what if TreeWidget tries to
detect the visibility of itself? This has been my question.
And thank you Mike, I think I have tried componentShown, but it seemed
never fired. Anyway I will try it again.
Have a nice day!
thao_chuan |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|