Article View: borland.public.jbuilder.java.language
Article #17054Re: Adding nodes to JTree
From: Jason Burton
Date: Wed, 16 Dec 1998 00:00
Date: Wed, 16 Dec 1998 00:00
19 lines
1203 bytes
1203 bytes
Leo Cohen wrote in message <3677EF96.BDBE2B67@cs.virginia.edu>...
>Using JTree, I can succesfully initialize a tree using the default tree
>model and DefaultMutableTreeNode. After the initialized tree is on the
>screen, how do I add a new node to the tree?
You use the methods of the root node (and any child nodes), rather than
using methods of the JTree itself. Example:
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root Node");
JTree myTree = new JTree(rootNode);
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Child Node");
rootNode.add(childNode);
See the help on DefaultMutableTreeNode for more methods to manipulate child
nodes.
Jason Burton
Technical Details
Message-ID:
<758s82$qss15@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3677EF96.BDBE2B67@cs.virginia.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,c4ccd4f3d2110752 X-Google-Attributes: gidf74b3,public From: "Jason Burton" <jasonb@tmscorp.com> Subject: Re: Adding nodes to JTree Date: 1998/12/16 Message-ID: <758s82$qss15@forums.borland.com> X-Deja-AN: 422945586 References: <3677EF96.BDBE2B67@cs.virginia.edu> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language