🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10665

SV: VERY basic JTree question...

#10665
From: Johan Forsberg
Date: Wed, 18 Aug 1999 00:00
31 lines
1744 bytes
Holger Stratmann <hs@cassiopeia.de> skrev i
diskussionsgruppsmeddelandet:37B97436.60A20FCB@cassiopeia.de...
> This is just for starters: How do I insert a couple of nodes into a
> JTree?
>
> e.g. what's the code for
> * Root
>   |- Parent 1
>   |  |- Child 11
>   |  '- Child 12
>   '- Parent 2
>      '- Child 21

DefaultMutableTreeNode root=new DefaultMutableTreeNode("Root");
DefaultTreeModel model=new DefaultTreeModel(root);
JTree tree=new JTree(model);

DefaultMutableTreeNode n=new DefaultMutableTreeNode("Parent 1");
model.insertNodeInto(n, root, 0);
model.insertNodeInto(new DefaultMutableTreeNode("Child 11"), n, 0);
model.insertNodeInto(new DefaultMutableTreeNode("Child 12"), n, 1);
n=new DefaultMutableTreeNode("Parent 2");
model.insertNodeInto(n, root, 1);
model.insertNodeInto(new DefaultMutableTreeNode("Child 21"), n, 0);

The DefaultMutableTreeNodes themselves have a large number of functions for
manipulating the tree structure. These are much more flexible then just
using insertNodeInto() as above. However, if you use those no messages will
be fired to the tree, and you must fire them yourself.
(eg. model.nodesWereInserted(...) )
Technical Details
Message-ID: <7pdons$17d1@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37B97436.60A20FCB@cassiopeia.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,a250cac0519badf0
X-Google-Attributes: gid111d45,public
From: "Johan Forsberg" <jfo@SPAM_SPAM_EGGS_SPAMstmf.se>
Subject: SV: VERY basic JTree question...
Date: 1999/08/18
Message-ID: <7pdons$17d1@forums.borland.com>
X-Deja-AN: 514123743
References: <37B97436.60A20FCB@cassiopeia.de>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.swing