JComboBox Search Question

Hello,

Small things again...

How to check (Search) if a given target token exists in a JComboBox list?. I am trying to find away to do it without looping from 0..getItemCount()

Any suggessions?
prainAsked:
Who is Participating?
 
objectsCommented:
Create your own own ComboListModel implementation with the necessary search methods.
Let me know if u need a hand.
0
 
CEHJCommented:
There isn't another way
0
 
CEHJCommented:
You could use a binary search, which would be better than O(n) but that would require your model be sorted
0
 
objectsCommented:
and u can always use gDefaultComboBoxModel.getIndexOf() method if that suits

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/DefaultComboBoxModel.html#getIndexOf(java.lang.Object)
0
 
CEHJCommented:
>>and u can always use gDefaultComboBoxModel.getIndexOf() method if that suits

That won't avoid looping of course - it just means that Java will do it instead of you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.