I am trying to add a node to my JTree. I do that like so:
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(event.getObjectThatHasChanged());
root.add(newNode);
((DefaultTreeModel) tree.getModel()).reload();
However, the tree itself doesnt update. Ive read posts that reload() is what you are supposed to call, but to no effect. Also please note this is being called on the EDT. Any ideas?
EDIT:
I have tried this approach:
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(event.getObjectThatHasChanged());
((DefaultTreeModel) tree.getModel()).
insertNodeInto(newNode, root, root.getChildCount() - 1);
Still no go. However, when I shut the program down and reopen it, the new node is there. (I persist my data).