Article View: borland.public.jbuilder.java.swing
Article #12173Re: JTree problem - adding nodes after root is displayed
From: Tom Ranz
Date: Tue, 09 Feb 1999 00:00
Date: Tue, 09 Feb 1999 00:00
46 lines
1736 bytes
1736 bytes
All:
The following goes work for me:
// int nodeCount is defined elsewhere.
public void addNode()
{
DefaultMutableTreeNode dmtn;
node3.add(dmtn = new DefaultMutableTreeNode("New Node " + ++nodeCount,
true));
int[] indexAry = new int[1];
indexAry[0] = node3.getIndex(dmtn);
DefaultMutableTreeNode[] nodeAry = new DefaultMutableTreeNode[1];
nodeAry[0] = dmtn;
DefaultTreeModel dtm = (DefaultTreeModel)myTree.getModel();
dtm.nodesWereInserted(node3, indexAry);
}
Tom
Torgeir Veimo wrote:
> Tom Ranz wrote:
> >
> > Hi,
> >
> > I have noticed when trying to add child nodes to an existing and
> > displayed root node multiple times that the new child nodes are added to
> > the root node but I cannot get them to display.
>
> You must inform the tree model that nodes were inserted. Use the
> fireTreeNodesInserted or something similar on either
> DefaultMutableTreeModel or DefaultTreeModel. You can get the model if
> you created the JTree with a node by using getModel() on the JTree
> instance I believe.
>
> --
> -Torgeir
Technical Details
Message-ID:
<36C04072.CC2ED525@mindspring.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36BF42DD.6CAA7C6A@mindspring.com> <36BF7370.6E0F3DFA@vertech.no>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,b6c9cb4d911d55be X-Google-Attributes: gid111d45,public From: Tom Ranz <teranz@mindspring.com> Subject: Re: JTree problem - adding nodes after root is displayed Date: 1999/02/09 Message-ID: <36C04072.CC2ED525@mindspring.com> X-Deja-AN: 442425681 Content-Transfer-Encoding: 7bit References: <36BF42DD.6CAA7C6A@mindspring.com> <36BF7370.6E0F3DFA@vertech.no> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing