This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
If I check fileTree.getSelectionPath() and fileTree.isExpanded(lastPath), both indicate that the path is indeed selected and expanded. However when the tree appears, it is not visibly expanded. I've made sure the TreePath does not end with a leaf node. I've tried updateUI and all sorts of repaint calls. Nothing seems to make a difference.
Hi. I can guess you does not put your code in the apropriate place. You can manipulate of your tree after you has you tree created and model set.
In this case setExpandedState does not work, because tree is not ready yet, but if you change like this:
it will work.
Hope it help [ November 10, 2004: Message edited by: Serghei Jelauc ]
SCJP 1.4 <br />SCBCD 1.3<br />SCWCD 1.4
Joined: Jun 28, 2004
Thanks. That actually didn't solve the problem but enabled me to identify the real problem. It leads to another question.
What I want to do is save the SelectedPath from an old tree. Then when I have a new tree with the same structure, automatically expand the previously selected path.
The problem I ran into is that if you set the selected path for one tree with a TreePath that came directly from another tree, even if they have the exact same logical structure, the new tree won't expand. It seems from my experiments that you must find the path you want in the current JTree.
However, I have been having trouble figuring out the best way to accomplish this.
Not sure if you or anyone else has an idea.
Joined: Jul 24, 2002
Hi. I do not understand what do you mean. Do you have two differrent trees with the same structure in your application? If so, may be you can try to use the row number for selected node. I mean:
and in your other tree (if it has the same structure):
I did not try it, but may be it will work;
Or may be you can create the base class wich extends JTree, and for both of your tree create two different classes wich will extend your base class. In this case the selected TrreePath will be the same object for both trees. And as the previous I did not try this. It's just my ideas.
Thanks for the ideas. The problem with the row number is that it is relative to visible rows. So row 3, for example, in a tree that is expanded is different from row 3 in a tree that is not expanded at all.
I'll figure something out now that I understand the basic problem better.