This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

sort jtree

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27289
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ;)
 
reply
    Bookmark Topic Watch Topic
  • New Topic