Article View: borland.public.jbuilder.java.swing
Article #8221JTree problems
From: Tom
Date: Sun, 15 Oct 2000 00:00
Date: Sun, 15 Oct 2000 00:00
32 lines
2246 bytes
2246 bytes
I have a tree with custom nodes and a custom treemodel. Nodes keep a vector
of their child node's data in addition to their own data information. When
the tree calls the treemodel for information about a itself or it's
children, the treemodel calls the corresponding node object for the
information. This all works like it's supposed to.
Now, when i want to add a new node (in response to the user clicking a node
with a vector of data objects) i just create a new data object and add it to
the vector and call the model's fireTreeNodesChanged( ). The new node
appears in the tree, but ONLY if the parent node was not expanded before i
added the new dataobject to the vector. If i then ask the treemodel about
the childcount() of the parent node it confirms that a new child had been
added. But when i try to set the selection to this node by constructing a
TreePath with
TreePath selectedPath = tree.getSelectionModel().getSelectionPath();
TreePath newPath(selectedPath.getLastSelectedComponent(),
this.getTreeModel.getChild(selectedPath.getLastSelectedComponent(),
this.getTreeModel().getChildCount(selectedPath.getLastPathComponent()));
or by any other means,
the new path is not valid. Do i need a reference to the the new node to
construct the new path and if so how can i do that beacause the call to
treeModel.getChild(..) eventually calls my parent node that constructs a NEW
node.
I debugged the application so that whenever the parent node's
getChild(index) gets called or i click a node the reference to the node
object gets printed. Then when i click the new node object i get a reference
that never got printed in a call to getChild(). So how did it get in the
tree in the first place?
If anyone encountered similiar problems i appreciate some words of wisdom.
S.S
Technical Details
Message-ID:
<39e869dd$1_2@dnews>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,e7dea336589724f,start X-Google-Attributes: gid111d45,public From: "Tom" <sverrir.sverrisson@islandia.is> Subject: JTree problems Date: 2000/10/15 Message-ID: <39e869dd$1_2@dnews> X-Deja-AN: 681380966 X-Trace: 14 Oct 2000 07:12:45 -0800, 62.145.157.208 Newsgroups: borland.public.jbuilder.java.swing X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4