if (!isEditable() && newSelectedItem != null) { int i, c; boolean resetSelectedItem = true; Object o; Object selectedItem = dataModel.getSelectedItem();  for (i=0,c=dataModel.getSize();i<c;i++) { o = dataModel.getElementAt(i); if (o.equals(selectedItem)) { resetSelectedItem = false; break; } }  if (resetSelectedItem) { if (dataModel.getSize() > 0) setSelectedIndex(0); else setSelectedItem(null); } }
    public void contentsChanged(ListDataEvent e) {        Object newSelectedItem = dataModel.getSelectedItem();        if ((lastSelectedItem == null && newSelectedItem != null)            || (lastSelectedItem != null && !lastSelectedItem.equals(newSelectedItem)))            selectedItemChanged();        if (!isEditable() && newSelectedItem != null) {            int i, c;            boolean resetSelectedItem = true;            Object o;            Object selectedItem = dataModel.getSelectedItem();                        for (i=0,c=dataModel.getSize();i<c;i++) {                o = dataModel.getElementAt(i);                if (o.equals(selectedItem)) {                    resetSelectedItem = false;                    break;                }            }            if (resetSelectedItem) {                if (dataModel.getSize() > 0)                    setSelectedIndex(0);                else                    setSelectedItem(null);            }        }    }