void () { registerKeyboardAction(e -> { DialogWrapper dialogWrapper; Object clientProperty; if (isPopupVisible()) { setPopupVisible(false); } else if ((clientProperty = getClientProperty(TABLE_CELL_EDITOR_PROPERTY)) instanceof CellEditor) { // If a combo box is inside editable table, then we need to cancel editing // and do not close heavyweight dialog container (if any) ((CellEditor)clientProperty).cancelCellEditing(); } else if ((dialogWrapper = DialogWrapper.findInstance(this)) != null) { dialogWrapper.doCancelAction(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); }