Reputation: 22200
I am developing a small desktop application in JAVA using Netbeans. I place a JTree and dynamically populating it. Every thing went fine now i want to achieve the following two things:
How do i achieve these two behaviors?
Upvotes: 2
Views: 5487
Reputation: 48105
Expand all nodes (arbitrary depth):
for (int i = 0; i < tree.getRowCount(); i++) {
tree.expandRow(i);
}
Select first leaf:
DefaultMutableTreeNode firstLeaf = ((DefaultMutableTreeNode)tree.getModel().getRoot()).getFirstLeaf();
tree.setSelectionPath(new TreePath(firstLeaf.getPath()));
Upvotes: 7