void (JComponent component) { @NlsSafe String actionName = "FCB_ESC"; Action action = new AbstractAction(actionName) { private static final long serialVersionUID = -4351240441578952476L; @Override public void actionPerformed(ActionEvent e) { popup.hide(); if (e.getSource() instanceof JTextField textField) { textField.setCaretPosition(textField.getCaretPosition()); } } }; component.getActionMap().put(actionName, action); component.getInputMap(JComponent.WHEN_FOCUSED) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), actionName); }