• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sort jtree

 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i successfully sorted my jtree alphabetically by implementing comparable in the defaultmutabletreenode but i am having a problem with a restriction in the 1st level.

if the node is labeld "CAR" it should always stop at the top (1st node) and if the label is HOUSE it should always stay as the last node of the first level nodes. the rest of the nodes will be sorted alphabetically.

how to do this within the compare() method in a short way. thanks.

currently it works if i manually do if statements if the label is CAR or HOUSE and check what the value of the compare method is. im looking for a simplified way if there is. thanks
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mark chester goking wrote:currently it works if i manually do if statements if the label is CAR or HOUSE and check what the value of the compare method is. im looking for a simplified way if there is. thanks

But that's what you said the rule was. I don't see how the implementation can be simpler than the rule.
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a bit confused.
Do you mean to say first level nodes under root should not be sorted, but their children should be?


 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi maneesh.
1st level nodes should be sorted, but if the string is CAR, it should always be the first node. if it is HOUSE is should always be the last node.

e.g.

root
-CAR
-- child1
-- child2
-AIRCRAFT
-- child1
-- child2
-BUILDING
-- child1
-- child2
-HOUSE
-- child1
-- child2

aircraft and building are sorted. while car and house are not. car should always be the first and house should always be the last
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for the moment, this is how i did it



just wondrin' if there's a simplier way to simplify it ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic