1. create a DefaultMutableTreeNode containing your root object as your tree root
2. create a DefaultTreeModel with the root
3. create a JTree using the model
4. create a tree manager to listen for tree events and apply it to the tree
5. to add nodes to the tree, add them via the model using myTreeModel.insertNodeInto(newChild,parent,parent.getChildCount())
6. to remove a node myTreeModel.removeNodeFromParent(currentlySelectedNode);
Point 5 is what people normally get wrong. It is possible to add nodes directly to other nodes on the tree, but it won't repaint properly.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.