Tool (@Nullable String toolId) { JComboBox comboBox = getComboBox(); if (toolId == null) { comboBox.setSelectedIndex(-1); return null; } for (int i = 0; i < comboBox.getItemCount(); i++) { final Object itemAt = comboBox.getItemAt(i); if (itemAt instanceof Tool && toolId.equals(((Tool)itemAt).getActionId())) { comboBox.setSelectedIndex(i); return (Tool)itemAt; } } return null; }