Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

How to Get Root Path in JTree

Thread view: 
Jason Cavett - 07 Feb 2007 16:02 GMT
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.
Michael Rauscher - 08 Feb 2007 09:46 GMT
> 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
[quoted text clipped - 5 lines]
> root, DefaultTreeModel *always* throws an exception because of this
> method...

Please provide the exception.

Bye
Michael
Jason Cavett - 08 Feb 2007 21:02 GMT
> > 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
[quoted text clipped - 10 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.