JTree question

Hi All,

I would like some help with the following question.

I need to remove a node from my JTree that has children. Can you use the JTree like a linked list - that is add the new node, point the children to it ad then delete the old parent node?

When I delete a node that has children, the children get deleted also.

How do you usually deal with the problem? I don't really want to have to requery the database to build part of the tree.

Thanks,

Jackie.

[507 byte] By [jackie_gomes] at [2007-9-27 15:47:56]
# 1

There are methods on the Tree Nodes that allow you to traverse the list of children. You should be able to traverse that list, remove the children, and add them to the new node. Once that's done, then you would remove the parent node. The trick is, once this is done you need to notify the TreeModel that the tree structure has changed so that the TreeView can display all the changes to the user.

It's late and I don't know the calls off the top of my head, but what you are asking is possible.

Andrew Wilcox

windowe at 2007-7-5 23:58:31 > top of Java-index,Desktop,Core GUI APIs...
# 2

hi ppl,

i have one serious problem need to be solved.

i have one dynamic tree in my GUI.it's dynamic one. the problem

is i want to remove one of the child node (first node) from its parent node at runtime.

i used this method parentnode.remove(0) .it removes its first child .but it is not removing from the tree view.it's showing the child node with broken link to its parent.

but when i doubleclick i mean when i collapse that parent it' getting vansihed.

i used all the methods remove(0),remove(treepath),and also removeFromParent

can anyone plz solve the problm

plz mail me the solution to this id.

harihere83@sify.com

waiting for reply

thanks

hari

harihere at 2007-7-5 23:58:31 > top of Java-index,Desktop,Core GUI APIs...
# 3

hi ppl,

i have one serious problem need to be solved.

i have one dynamic tree in my GUI.it's dynamic one. the problem

is i want to remove one of the child node (first node) from its parent node at runtime.

i used this method parentnode.remove(0) .it removes its first child .but it is not removing from the tree view.it's showing the child node with broken link to its parent.

but when i doubleclick i mean when i collapse that parent it' getting vansihed.

i used all the methods remove(0),remove(treepath),and also removeFromParent

can anyone plz solve the problm

plz mail me the solution to this id.

harihere83@sify.com

waiting for reply

thanks

hari

harihere at 2007-7-5 23:58:31 > top of Java-index,Desktop,Core GUI APIs...
# 4
You could use tree classes from dotuseful project - they were created to handle this. http://dotuseful.sourceforge.net/Denis Krukovsky http://dotuseful.sourceforge.net/
dkrukovsky at 2007-7-5 23:58:31 > top of Java-index,Desktop,Core GUI APIs...