This should be really easy. Each node in my JTree has several attributes which I now want to get at. I can get the selected path for my tree using getSelectionPath(), but I don't seem to be able to get at the node itself !! Thanks, Kate
kate damond
Ranch Hand
Joined: Apr 17, 2001
Posts: 77
posted
0
Ok, I figured that out now.
Next question is that I don't seem to be able to get at my nodes correctly. I get a DefaultMutableTreeNode, but I know that my nodes were MyTreeNodeObject when I put them there. So, how comes I can't cast back to MyTreeNodeObject ???
Cheers Kate
John Gallagher
Greenhorn
Joined: Aug 21, 2001
Posts: 6
posted
0
What kind of exception do you get when you try to cast it? The way that you show should work.
Vinod Venugopal
Ranch Hand
Joined: Dec 06, 2000
Posts: 148
posted
0
Why dont u put all ur nodes ( custom ) in a Vector, then run a search & when u get what u want pick it from the collection. This is how u would cast it to ur custom node type... DefaultMutableTreeNode currentNode =(DefaultMutableTreeNode)Tree.getLastSelectedPathComponent(); .... CustomNodeType currentItem = (CustomNodeType)currentNode.getUserObject(); this shud work