• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ordering of items in a combo box

 
Samantha O'Neill
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone.
I am using JComboBoxes to hold my origin and destination airport values and they are initialised at the start to display ANY.
What I've noticed though is that after a search has been done with different criteria than ANY, when I pull down the box to set the value for another search the items do not appear in the list in any particular order which means my ANY option could be anywhere instead of the very first option in the list where I would like it to be.
Has anyone any idea how to achieve this. I am using an extended DefaultComboBoxModel.
Much appreciated Sam
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
return a Set/TreeSet, which has a handy toArray method, which of course your combo box can be constructed with
 
Samantha O'Neill
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply but I already have my items in a combo box that's not really the porblem. I just wanted to know if there was a way I could always get my 'ANY' option to always be the first item in the list?
Many thanks Sam
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samantha O'Neill:
Thanks for the reply but I already have my items in a combo box that's not really the porblem. I just wanted to know if there was a way I could always get my 'ANY' option to always be the first item in the list?
Many thanks Sam


I meant by using a SortedSet you'd have them alphabetically sorted.
Oh yes, Any isn't neccessarily first, still that shouldn't be a problem, I add my All BLABLABLA just before adding the rest, and its always on top, then again maybe thats because I dont have any other records starting with A, and I dont use the SortedSet except on startup, I doubt thats a problem tho, give it a shot
 
Samantha O'Neill
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I see what you mean - thanks I'll give it a bash.
Cheers Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic