Search code examples
javaswingjtree

How can I reset a JTree?


I'm currently working with JTree, more precisely with CheckBoxTree, an inherited class created by JIDE. I need to find a way to reset the tree, meaning :

  • Clearing the selection
  • Erasing the nodes

I tried unsetting the Tree variable, the treeModel, and refreshing the UI, but it doesn't works.

Any ideas ?


Solution

  • Unsetting the variable alone won't help - all that will do is lose your copy of the reference to the JTree object.

    What you need to do remove the reference the containing object holds to the JTree - I assume you have it some kind of GridContainer or Layout object - remove it from the parent ojbect and then call updateUI on that object.