JComboBox Search Question

Posted on 2007-07-24
Last Modified: 2013-12-29

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?
Question by:prain
    LVL 86

    Expert Comment

    There isn't another way
    LVL 86

    Expert Comment

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

    Accepted Solution

    Create your own own ComboListModel implementation with the necessary search methods.
    Let me know if u need a hand.
    LVL 92

    Assisted Solution

    and u can always use gDefaultComboBoxModel.getIndexOf() method if that suits
    LVL 86

    Expert Comment

    >>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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    Core java. Please help me catch a bug. 5 51
    sumHeights  challenge 17 50
    mapShare challenge 13 40
    for i loop in grovy 1 25
    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now