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.
It sounds like your tree isn't detecting the
nodesWereRemoved
event that should be triggered by theremoveNodeFromParent(node);
method.Are you using the standard
DefaultTreeModel
andJTree
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 thenodesWereRemoved
event (in your customJTree
), or you're not triggering the event (in your customDefaultTreeModel
).If you're using the standard objects, try calling
JTree.revalidate();
andJTree.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 ofJTree
instead?