power_settings_new

how do I remove all childern for root node in JTree?

by
asked
0 votes
44 views
I am using JTree to display content. I would like to clear content/children of root node in JTree. How do I remove all childern for root node in JTree?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

answered by (171 points)
selected by
0 votes
 
Best answer
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
        root.removeAllChildren();
        model.reload();
add
...