JTree will expand but not collapse

D

dablick

I'm trying to write some buttons that entirely expand and entirely collapse
a JTree and would appreciate any help.

For some reason, the code I have will expand the tree, but not collapse it.

Here's the basic recursive tree walking function I use to do it. Why does
it only for the expand case and not the collapse case?

void walk_subtree(TreeNode n, boolean expand) {

Enumeration e = n.children();

while (e.hasMoreElements()) {
DefaultMutableTreeNode c = (DefaultMutableTreeNode)
e.nextElement();
TreePath tp = cvt2(c);

if (expand) {
jTree1.expandPath(tp);
}
else {
jTree1.collapsePath(tp);
}

walk_subtree(c, expand);
}
}
 
C

Christian Kaufhold

dablick said:
I'm trying to write some buttons that entirely expand and entirely collapse
a JTree and would appreciate any help.

For some reason, the code I have will expand the tree, but not collapse it.

Here's the basic recursive tree walking function I use to do it. Why does
it only for the expand case and not the collapse case?


collapsePath also expands the parent path of the path to collapse.

Use post-order walk for collapsePath.



Christian
 
D

dablick

Yep. That was it.

Thanks,

db

Christian Kaufhold said:
collapsePath also expands the parent path of the path to collapse.

Use post-order walk for collapsePath.



Christian
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top