开发者

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 :

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

Any ideas ?


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.


For erasing the nodes you should get the tree model and clear it or set a new tree model.

To clear the selection, call clearSelection() on the tree (note that setModel(...) already calls clearSelection() so if you want to do both together, just set a new model and repaint).


Just rebuild the tree at the beginning of each iteration.

Something of this sort

RootNode=new CheckBoxTreeNode("root");
CheckBoxTree= new CheckBoxTree(RootNode);

would do the trick. No need to call updateUI. Hope this help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜