Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JTree? 1

Status
Not open for further replies.

fmsousa

IS-IT--Management
Nov 24, 2000
28
PT
Hi! Can anyone tell me how to build a JTree?? if u already done some JTrees, please send it to me. Thanks!!!
 
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.

Bon chance! :) My home ----> My company ->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top