0

I've read plenty of java Swing forums or questions and none of them have the right answers. I am trying to dynamically select a node in a JTree by searching for it using a search panel based on its property.

My jtree allows single selection model. (SINGLE_TREE_SELECTION).

jTree.setExpandsSelectedPaths(true);
// jTree.expandPath(treePath);
jTree.setSelectionPath(treePath);
jTree.scrollPathToVisible(treePath);

I know the node is being selected and a call to jTree.getSelectionPath() shows the expected treePath. The problem is that graphically the treePath is neither expanded nor the specific searched node is highlighted.

TreePath is correct, and the node is being selected. The branch is just not being expanded and the node is not being highlighted. The node is not highlighted even when the branch is already in an expanded state.

Can anyone please help.

I am using Java 1.5

Thanks,
Bob

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by hemanthjava
0

Well, that selection call should work. Are you certain the TreePath includes all nodes up to and including the one you want to select?

0

Well, that selection call should work. Are you certain the TreePath includes all nodes up to and including the one you want to select?

yes the treepath is prefectly fine and includes all the nodes upto the selection

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.