Auto scroll when a JTree's node expand

A

Allan Valeriano

Hi,

I have JSplitPane, where the left panel is a JScrollPane with a JTree
inside, and the right panel is a JTable.

This is supposed to be something like the windows explorer, where I
have a tree representing folders on the left and the children listed
on the right. That way, when I double click a node on the right, the
node representing it should expand on the tree and get selected.

This part is working fine, but when I expand a node which is too deep
in the tree, it gets hidden. I'd like to auto scroll the bar, so the
selected node would be visible.
Anybody knows how can I do that? I hope I didn't make it too confusing
to understand.

thanks in advance for any help.
 
H

Hunter Gratzner

This part is working fine, but when I expand a node which is too deep
in the tree, it gets hidden. I'd like to auto scroll the bar, so the
selected node would be visible.
Anybody knows how can I do that? I hope I didn't make it too confusing
to understand.

JTree has a method for this. Read the API documentation.
 
Joined
May 12, 2012
Messages
1
Reaction score
0
Here is the code

DefaultMutableTreeNode top=new DefaultMutableTreeNode("Table of contents");
JTree tree = new JTree(top);
tree.setScrollsOnExpand(true);
JScrollPane treeView = new JScrollPane(tree);
treeView.setBounds(as you wish);
yourcontainer.add(treeView);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top