Link to home
Start Free TrialLog in
Avatar of prain
prainFlag for United States of America

asked on

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

There isn't another way
You could use a binary search, which would be better than O(n) but that would require your model be sorted
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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