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