File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes jtree not scrolling to selected node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jtree not scrolling to selected node" Watch "jtree not scrolling to selected node" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jtree not scrolling to selected node