File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Ordering of items in a combo box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Ordering of items in a combo box" Watch "Ordering of items in a combo box" New topic
Author

Ordering of items in a combo box

Samantha O'Neill
Greenhorn

Joined: Apr 15, 2003
Posts: 26
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

Joined: Mar 26, 2002
Posts: 442
return a Set/TreeSet, which has a handy toArray method, which of course your combo box can be constructed with
Samantha O'Neill
Greenhorn

Joined: Apr 15, 2003
Posts: 26
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

Joined: Mar 26, 2002
Posts: 442
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

Joined: Apr 15, 2003
Posts: 26
Ok I see what you mean - thanks I'll give it a bash.
Cheers Sam
 
Consider Paul's rocket mass heater.
 
subject: Ordering of items in a combo box