Board index » jbuilder » Collapse a JTree

Collapse a JTree


2005-07-28 10:59:14 PM
jbuilder24
Hi,
I have a problem to "clear my tree".
Typical tree (visible as is):
top --- node1 --- leaf1
| |- leaf2
|
|-- node2 --- leaf3
|- leaf4
User has node1 selected and click a RadioButton.
Now I want to collapse the tree so that top and node1 and node2 are visible.
I have tried with:
TreePath top = tree.getPathForRow(1);
tree.fireTreeCollapsed(top);
tree.setSelectionRow(0);
Problem is that leaf3 & 4 are still visible
If I try with row=0 only top is visible. I then tried to expand on row=1
but nothing happened.
Any hints?
 
 

Re:Collapse a JTree

Hi Magnus,
I was hoping someone more knowledgeable than me would answer, as I never did
quite figure out why this works, but it does seem to work for me.
tree.collapsePath(top);
tree.updateUI();
Arth
"Magnus" < XXXX@XXXXX.COM >wrote in message
Quote
Hi,

I have a problem to "clear my tree".

Typical tree (visible as is):

top --- node1 --- leaf1
| |- leaf2
|
|-- node2 --- leaf3
|- leaf4

User has node1 selected and click a RadioButton.
Now I want to collapse the tree so that top and node1 and node2 are
visible.

I have tried with:
TreePath top = tree.getPathForRow(1);
tree.fireTreeCollapsed(top);
tree.setSelectionRow(0);

Problem is that leaf3 & 4 are still visible

If I try with row=0 only top is visible. I then tried to expand on row=1
but nothing happened.

Any hints?
 

Re:Collapse a JTree

I should have added as you asked the question
TreePath top = tree.getPathForRow(0);
tree.collapsePath(top);
tree.updateUI();
 

{smallsort}