How do I programaticlly select a tree node in my JTree after it's just
been created and added to my tree. I'm trying to select it (I'm
guessing this means highlighted and selected as if the user just
clicked on it) by the following, but this isn't working.
[code]
// create new node and add to tree
DefaultMutableTreeNode myNode = addNode(getMyRoot(), myInfo, true);
// get the path from the root to the node
Object[] objPath = myNode.getUserObjectPath();
// and convert it to a Treepath, then select it.
TreePath tPath = new TreePath(objPath);
getTree().setSelectionPath(tPath);
[/code]
Thomas Weidenfeller - 31 May 2006 09:18 GMT
> How do I programaticlly select a tree node in my JTree after it's just
> been created and added to my tree. I'm trying to select it (I'm
> guessing this means highlighted and selected as if the user just
> clicked on it) by the following, but this isn't working.
[...]
> Object[] objPath = myNode.getUserObjectPath();
getUserObjectPath() does not do what you think it does. Check the API
documentation. You want getPath().
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/