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 / GUI / August 2004

Tip: Looking for answers? Try searching our database.

move nodes up or down in a JTree/TreeModel?

Thread view: 
Tim - 23 Aug 2004 14:07 GMT
Hi,

no info found with google, but I hope anyone here has experience with
changing a JTree / TreeModel. What I want, is to move a node, with his
children of course, up or down the tree one place, when the up/down button
is pressed. I have some experience with adding nodes and deleting now, but
the only sollution I see, is rather radical: deleting all nodes after the
one to move down, adding the one after the selected node, adding the node
itself again and then adding the rest (for moving down), similar algorithm
to move up. Are there any better solutions to this?

TIA,
Tim
ak - 23 Aug 2004 14:15 GMT
> no info found with google, but I hope anyone here has experience with
> changing a JTree / TreeModel. What I want, is to move a node, with his
[quoted text clipped - 4 lines]
> itself again and then adding the rest (for moving down), similar algorithm
> to move up. Are there any better solutions to this?
wrong way,
you just add node you want to move to proper parent - thats all.
You should also tell TreeModel that nodes were removed/added.

Signature

Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader

Tim - 23 Aug 2004 14:48 GMT
> you just add node you want to move to proper parent

I don't think I made myself clear. When I say, moving up or down, I mean
that they stay within the same parent, but the order of the children
changes. When adding a node, it is always added at the end of the list of
children. But if the node I want to move up or down, is the 5th node in the
list of children, the I want to make it either the 4th or the 6th node.

greetings
Tim
ak - 23 Aug 2004 15:30 GMT
> I don't think I made myself clear. When I say, moving up or down, I mean
> that they stay within the same parent, but the order of the children
> changes. When adding a node, it is always added at the end of the list of
> children. But if the node I want to move up or down, is the 5th node in the
> list of children, the I want to make it either the 4th or the 6th node.

use MutableTreeNode#insert(MutableTreeNode node, int index);

Signature

Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader

Tim - 23 Aug 2004 16:53 GMT
> use MutableTreeNode#insert(MutableTreeNode node, int index);

It had been a while since I used the JTree, indeed, when you add a node,
you can choose at which position it is inserted. Sorry for the stupid
question. :-S

greetz
Tim
Christian Kaufhold - 23 Aug 2004 15:32 GMT
> no info found with google, but I hope anyone here has experience with
> changing a JTree / TreeModel. What I want, is to move a node, with his
[quoted text clipped - 4 lines]
> itself again and then adding the rest (for moving down), similar algorithm
> to move up. Are there any better solutions to this?

What makes you think you can add nodes only at the end?

Christian
Tim - 23 Aug 2004 16:53 GMT
> What makes you think you can add nodes only at the end?

It had been a while since I used the JTree functions, indeed, when you add
a node, you can choose at which position it is inserted. Sorry for the
stupid question. :-S

greetz
Tim


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.