This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes problem expanding JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem expanding JTree" Watch "problem expanding JTree" New topic

problem expanding JTree

robyn byrd

Joined: Oct 26, 2005
Posts: 9
I am progammatically expanding a JTree but the last most nodes do not expand. I'm using code I found on this forum: tree.getRowCount(), tree.expandRow(i), etc. I've also tried expandPath, but the problem remains.

I'm building a tree that looks like this:
- S1
| |
| - A1
| |
| - A2
- S2
- A3
- A4
First I create node S1 and add to root. Then I create node A1, add to S1, then create A2 and add to A1. Tree appears expanded during these operations.
Then I create S2 and add to root. No problems. However, when I add A3 to S2, node S2 is not expanded. When I add A4 to A3, S2 remainds collapsed. Can anyone tell me what's happening and how I make all rows of the tree to be expanded when new nodes are added. I notice that tree.getRowCount() returns 3, so it doesn't seem to count rows for the 'A' nodes.
Thanks for your help.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
"getRowCount" only returns the number of visible rows.
Expanding or Collapsing All Nodes in a JTree Component
robyn byrd

Joined: Oct 26, 2005
Posts: 9
Thanks very much. That did the trick!
It is sorta covered in the JavaRanch Style Guide.
subject: problem expanding JTree
Similar Threads
Expanding a Specific Node in JTree
Help with refresh on JTree
JTree class
JTree in Browser