Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree setFocus()

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i setFocus() to a node in JTree?
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
tree.setSelectionRow(rownumber)
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic