Article View: borland.public.jbuilder.java.swing
Article #9225Adding 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
41 lines
1759 bytes
1759 bytes
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.
Technical Details
Message-ID:
<8ec3qm$pge$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ea35aa225c9965b5,start X-Google-Attributes: gid111d45,public From: josa04@my-deja.com Subject: Adding nodes to a JTree, changes in the model not reflected in the tree Date: 2000/04/28 Message-ID: <8ec3qm$pge$1@nnrp1.deja.com> X-Deja-AN: 616765087 X-Http-Proxy: 1.0 x38.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 13:31:02 2000 GMT X-MyDeja-Info: XMYDJUIDjosa04 Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I)