boolean () { final JComboBox[] candidates = { myModuleComboBox, myScopeCombo.getComboBox(), myDirectoryChooser.getComboBox() }; for (JComboBox candidate : candidates) { if (candidate.isPopupVisible()) { candidate.hidePopup(); return true; } } return false; }