File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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!
I agree. Here's the link:
subject: problem expanding JTree
jQuery in Action, 3rd edition