Java JComboBox Item findComboBoxItemForString(final JComboBox box, final String searchString)

Here you can find the source of findComboBoxItemForString(final JComboBox box, final String searchString)

Description

DOCUMENT ME!

License

LGPL

Parameter

Parameter Description
box DOCUMENT ME!
searchString DOCUMENT ME!

Return

DOCUMENT ME!

Declaration

public static int findComboBoxItemForString(final JComboBox box, final String searchString) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.swing.ComboBoxModel;

import javax.swing.JComboBox;

public class Main {
    /**/*  w  ww.j  a v  a 2 s. com*/
     * DOCUMENT ME!
     *
     * @param   box           DOCUMENT ME!
     * @param   searchString  DOCUMENT ME!
     *
     * @return  DOCUMENT ME!
     */
    public static int findComboBoxItemForString(final JComboBox box, final String searchString) {
        if ((box != null) && (searchString != null)) {
            final ComboBoxModel model = box.getModel();
            if (model != null) {
                for (int i = model.getSize(); --i >= 0;) {
                    if (searchString.equals(String.valueOf(model.getElementAt(i)))) {
                        return i;
                    }
                }
            }
        }
        return -1;
    }
}

Related

  1. addFirstItem(JComboBox combobox, T item)
  2. addHeadersaveFileTypeItemsTo(JComboBox combo)
  3. addItems(JComboBox comboBox, Iterable items)
  4. contains(final JComboBox comboBox, final Object item)
  5. fillCombo(JComboBox comboBox, Collection items)
  6. getDataIndexFromComboBox(JComboBox cbb, String dta)
  7. getItems(JComboBox box)
  8. getItems(JComboBox comboBox)
  9. insertIntoCombo(JComboBox combo, Object item)