I'm currently trying
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
DefaultMutableTreeNode child = new DefaultMutableTreeNode("String");
if (model.getIndexOfChild(root, child) == -1) {
model.insertNodeInto(child, root, root.getChildCount());
}
model.reload(root);
I've also tried using the 'isNodeChild()' method in MutableTreeNode
instead of the getIndexOfChild()
method on the TreeModel.
This seems like it should be a pretty trivial thing to do: Take a given node in the tree and see if there is a child node with the specified value (in this case, a String
) that already exists. If there is, do not add a new child node. Otherwise, add the node as a child.
Suggestions?