I have a JTree (myTree) and in another class, I have a DefaultMutableTreeNode which was taken from myTree.
In a certain function, I want the JTree to highlight the node.
I tried:
myTree.setSelectionPath(new TreePath(treeNode));
but visually nothing is happening.
any ideas?
UPDATE:
I have also another JTable which is rendered based on the selected treeNode in myTree. The table is updating correctly. It’s just the myTree which refused to update visually.
You need to use the actual tree path of the node. Not just an instance of TreePath:
Also, the javadoc says:
So make sure that
getExpandsSelectedPathsis true.