defaultTreeModel nodes removed still shown in table

328 views Asked by At

I am trying to remove nodes from a DefaultTreeModel. If I try to remove a single node, it doesn't get removed from the GUI. If I remove 2 nodes, only 1 of them is getting removed, etc.

I am using removeNodeFromParent(node); to remove the nodes.

Could someone please help me with this problem.

1

There are 1 answers

0
wattostudios On

It sounds like your tree isn't detecting the nodesWereRemoved event that should be triggered by the removeNodeFromParent(node); method.

Are you using the standard DefaultTreeModel and JTree objects? If so, they should automatically refresh when doing a removal. If you've written a custom of either class, you're probably not handling the nodesWereRemoved event (in your custom JTree), or you're not triggering the event (in your custom DefaultTreeModel).

If you're using the standard objects, try calling JTree.revalidate(); and JTree.repaint(); after you remove the node, to force the tree to be repainted from your model change.

A final suggestion, have you tried any of the removeXXX() methods of JTree instead?