/** * Returns the index of the currently selected item in the list. * * @return the selected item in the list or -1 if no item is selected or if * the currently selected item (text field) is not in the list */ public int getSelectedIndex() { Object selected = dataModel.getSelectedItem(); if (selected == null) return -1; int itemCount = getItemCount(); for (int i = 0; i < itemCount; i++) { if (selected.equals(getItemAt(i))) { return i; } } return -1; }