Article View: borland.public.jbuilder.java.swing
Article #9226Re: Adding nodes to a JTree, changes in the model not reflected in the tree
From: josa04
Date: Fri, 28 Apr 2000 00:00
Date: Fri, 28 Apr 2000 00:00
62 lines
2276 bytes
2276 bytes
Hi,
additional information:
In JBuilder3 the code seem to work. VisualAge still uses JDK1.1.7 (?)
and imports com.sun.java.swing.tree.* instead of javax.swing.tree.*. Can
that be the problem?
Anyone got any ideas on how to solve this?
Regards
//Johan
In article <8ec3qm$pge$1@nnrp1.deja.com>,
josa04@my-deja.com wrote:
> Hi,
>
> I'm trying to use a JTree and add nodes dynamically (I want to fetch
the
> data and add it to the tree dynamically when a node is expanded). I
> don't seem to get the tree to reflect th changes in the model.
>
> I define a JTree:
> rootNode = new DefaultMutableTreeNode("Root Node");
> treeModel = new DefaultTreeModel(rootNode);
> ivjJTree1 = new com.sun.java.swing.JTree(treeModel);
>
> I have a test function that adds a node:
> void addChild(String a)
> {
> DefaultMutableTreeNode childNode = new
> DefaultMutableTreeNode(a);
> treeModel.insertNodeInto(childNode, rootNode,
> rootNode.getChildCount());
> // Make sure the user can see the new node.
> ivjJTree1.expandPath(new TreePath(rootNode.getPath()));
> ivjJTree1.scrollPathToVisible(new
> TreePath(childNode.getPath()));
> }
>
> If this function is called BEFORE the tree is displayed on the screen
> the changes are visible,
> but if it is called when the tree is already visible the changes are
not
> reflected in the tree.
>
> I'm using Visual Age.
>
> Anyone got any ideas?
>
> Thanks in advance.
>
> Regards
> //Johan Samuelsson
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID:
<8ec8i3$v4t$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8ec3qm$pge$1@nnrp1.deja.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ea35aa225c9965b5 X-Google-Attributes: gid111d45,public From: josa04@my-deja.com Subject: Re: Adding nodes to a JTree, changes in the model not reflected in the tree Date: 2000/04/28 Message-ID: <8ec8i3$v4t$1@nnrp1.deja.com> X-Deja-AN: 616793424 References: <8ec3qm$pge$1@nnrp1.deja.com> X-Http-Proxy: 1.0 x33.deja.com:80 (Squid/1.1.22) for client 164.10.32.33 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Fri Apr 28 14:51:54 2000 GMT X-MyDeja-Info: XMYDJUIDjosa04 Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I)