void (@Nullable Object selection) { if (selection == null) return; JComboBox<ScopeDescriptor> combo = getComboBox(); DefaultComboBoxModel<ScopeDescriptor> model = (DefaultComboBoxModel<ScopeDescriptor>)combo.getModel(); for (int i = 0; i < model.getSize(); i++) { ScopeDescriptor descriptor = model.getElementAt(i); if (selection instanceof String && selection.equals(descriptor.getDisplayName()) || selection instanceof SearchScope && descriptor.scopeEquals((SearchScope)selection)) { combo.setSelectedIndex(i); break; } } }