Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JComboBox Search Question

Posted on 2007-07-24
5
Medium Priority
?
247 Views
Last Modified: 2013-12-29
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?
0
Comment
Question by:prain
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 19558389
There isn't another way
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19558400
You could use a binary search, which would be better than O(n) but that would require your model be sorted
0
 
LVL 92

Accepted Solution

by:
objects earned 375 total points
ID: 19560713
Create your own own ComboListModel implementation with the necessary search methods.
Let me know if u need a hand.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 375 total points
ID: 19560717
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 19560741
>>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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question