Here you can find the source of getDataIndexFromComboBox(JComboBox cbb, String dta)
public static int getDataIndexFromComboBox(JComboBox cbb, String dta)
//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; } }