| Author |
jtree not scrolling to selected node
|
pavan in
Ranch Hand
Joined: Oct 22, 2002
Posts: 64
|
|
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
Joined: Sep 28, 2000
Posts: 508
|
|
scrollPane.getViewport().scrollRectToVisible([rectOfTheTreeCell]); (works fine) or maybe: scrollbar.setValue([rowOfTreeCell]); (never tried this last one, though) Chantal
|
 |
pavan in
Ranch Hand
Joined: Oct 22, 2002
Posts: 64
|
|
|
How do I get the Rectangle of tree node?
|
 |
Bhagya Tangutur
Ranch Hand
Joined: Oct 21, 2002
Posts: 88
|
|
You can use scrollPathToVisible(treePath) method in Tree or ScrollPathToVisible(int row).. you can get TreePath either from Node object itself or From DefaultTreeModel.
|
Sun Certified Java Programmer
|
 |
pavan in
Ranch Hand
Joined: Oct 22, 2002
Posts: 64
|
|
|
Thanks Kiran. That works just as I wanted.
|
 |
 |
|
|
subject: jtree not scrolling to selected node
|
|
|