Java JComboBox Item getDataIndexFromComboBox(JComboBox cbb, String dta)

Here you can find the source of getDataIndexFromComboBox(JComboBox cbb, String dta)

Description

get Data Index From Combo Box

License

Open Source License

Declaration

public static int getDataIndexFromComboBox(JComboBox cbb, String dta) 

Method Source Code

//package com.java2s;
/*/*w w  w.ja v  a 2 s .  c  om*/
 * Copyright 2005, 2009 Cosmin Basca.
 * e-mail: cosmin.basca@gmail.com
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

public class Main {
    public static int getDataIndexFromComboBox(JComboBox cbb, String dta) {
        for (int i = 0; i < ((DefaultComboBoxModel) cbb.getModel()).getSize(); i++) {
            String data = (String) ((DefaultComboBoxModel) cbb.getModel()).getElementAt(i);
            if (data.equals(dta))
                return i;
        }

        return -1;
    }
}

Related

  1. addHeadersaveFileTypeItemsTo(JComboBox combo)
  2. addItems(JComboBox comboBox, Iterable items)
  3. contains(final JComboBox comboBox, final Object item)
  4. fillCombo(JComboBox comboBox, Collection items)
  5. findComboBoxItemForString(final JComboBox box, final String searchString)
  6. getItems(JComboBox box)
  7. getItems(JComboBox comboBox)
  8. insertIntoCombo(JComboBox combo, Object item)
  9. items(JComboBox comboBox)