How do I know which TreeNode it was? Can I use getSource(), or, like I'm thinking, will it return the JTree itself as the source no matter Node is being selected?
Say I have a DefaultMutableTreeNode?
DefaultMutableTreeNode dmtn, dmtn2;
dmtn = new DefaultMutableTreeNode("Top element 1", true);
dmtn2 = new DefaultMutableTreeNode("Sub element 1A", false);
Now, can I try, assuming I have a TreeSelectionEvent e
if (e.getSource() == dmtn2)
// do something
I'm not sure how to work the TreePath thing with a TreeNode.
I see that I might be able to get it to work with getPathComponent(int index) but will the getSource() work as well? Just wondering.
What will getPathComponent() be returning, the data of the Tree, a String, or the TreeNode component? How do I know if this TreeNode is selected? I don't want it triggering the thing automatically without being selected.
Or do I use JTree's getLastSelectionPathComponent() or whatever it was called?
If you were to read the API for TreeSelectionListener, you would find a link to the tutorial on How to Write a Tree Selection Listener. At the top of that page is an example that details the course you need to follow.
There are no new questions, but there may be new answers.
Darryl Burke wrote:If you were to read the API for TreeSelectionListener, you would find a link to the tutorial on How to Write a Tree Selection Listener. At the top of that page is an example that details the course you need to follow.
Suppose I wanted to have more than one path visible at a time though?
sub sub node
sub sub 2 node
sub sub 3 node
And I wanted sub sub 2 node, when selected, to do something, but I wanted it possible to display all the tree paths and not block it so that only one can show at a time.