Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to Get Root Path in JTree

Reply
Thread Tools

How to Get Root Path in JTree

 
 
Jason Cavett
Guest
Posts: n/a
 
      02-07-2007
I am currently adding nodes a JTree. I want the user to have the
ability to add a node to the root node which is *not* visible (AKA - I
had the root node). Basically, this means that when the user has no
nodes selected and they try to add a new node (via a menu), it should
automatically go to the root node.

The problem I'm having is that although I can get the path for the
root, DefaultTreeModel *always* throws an exception because of this
method...

--
public void nodesWereInserted(TreeNode node, int[] childIndices) {
if(listenerList != null && node != null && childIndices != null
&& childIndices.length > 0) {
int cCount = childIndices.length;
Object[] newChildren = new Object[cCount];

for(int counter = 0; counter < cCount; counter++)
newChildren[counter] = node.getChildAt(childIndices[counter]);
fireTreeNodesInserted(this, getPathToRoot(node), childIndices,
newChildren);
}
}
--


Basically, what happens is that, when the DefaultTreeNode tries to
fire that a new node was inserted, it is still holding the "path" to
the root node. Since the root node isn't showing, that path's row
value is -1.

Is there any way to add a new node to the root node, even though that
root node is not visible?


Thanks.

 
Reply With Quote
 
 
 
 
Michael Rauscher
Guest
Posts: n/a
 
      02-08-2007
Jason Cavett wrote:
> I am currently adding nodes a JTree. I want the user to have the
> ability to add a node to the root node which is *not* visible (AKA - I
> had the root node). Basically, this means that when the user has no
> nodes selected and they try to add a new node (via a menu), it should
> automatically go to the root node.
>
> The problem I'm having is that although I can get the path for the
> root, DefaultTreeModel *always* throws an exception because of this
> method...


Please provide the exception.

Bye
Michael
 
Reply With Quote
 
 
 
 
Jason Cavett
Guest
Posts: n/a
 
      02-08-2007
On Feb 8, 4:46 am, Michael Rauscher <(E-Mail Removed)> wrote:
> Jason Cavett wrote:
> > I am currently adding nodes a JTree. I want the user to have the
> > ability to add a node to the root node which is *not* visible (AKA - I
> > had the root node). Basically, this means that when the user has no
> > nodes selected and they try to add a new node (via a menu), it should
> > automatically go to the root node.

>
> > The problem I'm having is that although I can get the path for the
> > root, DefaultTreeModel *always* throws an exception because of this
> > method...

>
> Please provide the exception.
>
> Bye
> Michael


Thanks for the response. After working with my code a bit more, I
found a much more elegant solution which didn't require any of this.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
JTree Selection lost when JTree looses focus jumpz Java 3 11-12-2007 03:55 PM
How do you build a JTree with no root whatsoever (or its placeholder space)? lbrtchx@hotmail.com Java 2 08-11-2007 01:54 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
How to create a JTree with multiple root node? Allen Java 4 07-14-2006 12:54 AM



Advertisments