Reputation: 87
I have a JTree
where children are instances of my class inheriting from DefaultMutableTreeNode
.
At the beginning the tree has 10 nodes with two levels. Then I add children into some nodes, using add()
method in my class. Then I reload my tree model:
tree.setModel(root) // root is an instance of my class.
The children are added and everything works fine. But a problem appears when I want to set the selection path (expanding added children using tree.setSelectionPath(path)
). Then most nodes are truncated as if they were too long (I see an ellipsis like node).
How can this problem be solved. After commenting setSelectionPath(path)
line and expanding the nodes manually, everything works fine.
Upvotes: 2
Views: 353
Reputation: 101
After having the same problem with OpenJDK 11, the following fix works for me:
tree.expandPath(somePath);
tree.invalidate();
The key is invalidate()
telling Swing that the component has to be laid out again. For more details, see Difference between validate(), revalidate() and invalidate() in Swing GUI.
Upvotes: 1