1. Remove the TreeSelectionListeners from the existing checkboxtree selection model.
2. Set the new tree model.
3. Add the new selection listener to the checkboxtree selection model.
4. Programatically select the root node (digin is enabled).
What happens then is, the moment I refresh a node in the tree to update the color or some other attribute, a valueChanged event is getting fired for the root of the tree, and it says that everything is unchecked, even though they show as being checked. This only happens once, further updates to the tree don't trigger this problem.
Currently I am able to work around the problem with this block of code:
- Code: Select all
final DefaultTreeModel tmodel = (DefaultTreeModel) tree.getModel();
tmodel.nodeChanged(rootnode);
final CheckBoxTreeSelectionModel smodel = tree.getCheckBoxTreeSelectionModel();
smodel.addTreeSelectionListener(selection_listener);
Basically, I call nodeChanged on the root DefaultMutableTreeNode even though nothing has changed. After that I add the selection listener.
Thanks in advance for any pointers.