🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
1 messages
1 total messages Started by jgay Wed, 02 Nov 2005 06:12
Jtree sorting nodes causes collapse of paths
#407
Author: jgay
Date: Wed, 02 Nov 2005 06:12
32 lines
2513 bytes
I've got a tree, many nodes, many depths. I'd like to sort it. My
present algorithm is to traverse the tree and sort the list of children
of each node. Once I sort the children, obviously the indexes have
changed, so you must correct them.

I've tried:

remove all children from the parent
add the children in sorted order

If I do that using something like parent.remove and parent.insert,
thats fine as long as no children UNDER those children have been
expanded. If they have, then I'm not accounting for them and thus the
tree continues to show those children under the wrong nodes once the
sorted nodes are added.

If I do that using something like model.removeNodeFromParent and
model.insertNodeInto, then the entire tree will collapse up to the node
sorted on.

Either way sucks!

I've also tried passing Arrays.sort my own comparator that, depending
on the compare outcome, will do the removeFromParent and insertNodeInto
on the fly. This results in NOT collapsing the entire tree (probably
because all nodes are never removed) however it seems like on a
descending sort the nodes get messed up. I assumed this was because I
was reordering them on the fly in the tree...but now that I'm thinking
about it, maybe I was doing something else wrong.

In any case, is there a standard proceedure for doing this? Why does it
seem so difficult? I've spent a good two days on this. Crazy!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads