🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #407

Jtree sorting nodes causes collapse of paths

#407
From: 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!
Technical Details
Message-ID: <1130911933.654058.139830@z14g2000cwz.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,6137f6aea9b73c9,start
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail
From: jgay@bluefire.org
Newsgroups: borland.public.jbuilder.java.swing
Subject: Jtree sorting nodes causes collapse of paths
Date: 1 Nov 2005 22:12:13 -0800
Organization: http://groups.google.com
Lines: 33
Message-ID: <1130911933.654058.139830@z14g2000cwz.googlegroups.com>
NNTP-Posting-Host: 24.8.232.214
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1130911938 29149 127.0.0.1 (2 Nov 2005 06:12:18 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 2 Nov 2005 06:12:18 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: z14g2000cwz.googlegroups.com; posting-host=24.8.232.214;
   posting-account=MpNvxQ0AAABpBHS07TZTpTcoVxFi2i0b