jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes JTree setFocus() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree setFocus()" Watch "JTree setFocus()" New topic

JTree setFocus()

Chinmay Bajikar
Ranch Hand

Joined: Dec 08, 2001
Posts: 159
How do i setFocus() to a node in JTree?

The strength of the Wolf is the pack & the strength of the pack is the wolf....Rudyard Kipling
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
When you say "setFocus to a node" are you implying showing a node selected?
In that case, you can do so by:
1) If you know the row no. you can write
2) If you know the node, then
tree.setSelectionPath( new TreePath(node.getPath()) );
Then if you want to set focus to the tree pane then call pane.setFocus where pane is the container containing the tree.

- Vinod<br />-------<br />SCJP2
I agree. Here's the link: http://aspose.com/file-tools
subject: JTree setFocus()
It's not a secret anymore!