Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jtree not scrolling to selected node

 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jtree inside scroll pane. Initially,when the jtree is displayed, a node is preselected. but, since the jtree is big, the selected node is not visible to user at the start. In order to see the selected node, user has to scroll manually. Is there a way to make the scroll pane (or jtree) scroll to the selected node?
Thanks.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scrollPane.getViewport().scrollRectToVisible([rectOfTheTreeCell]);
(works fine)
or maybe:
scrollbar.setValue([rowOfTreeCell]);
(never tried this last one, though)
Chantal
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get the Rectangle of tree node?
 
Bhagya Tangutur
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use scrollPathToVisible(treePath) method in Tree or ScrollPathToVisible(int row)..
you can get TreePath either from Node object itself or From DefaultTreeModel.
 
pavan in
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kiran. That works just as I wanted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic