void (final JComponent component) { final KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0); final InputMap inputMap = component.getInputMap(); final ActionMap actionMap = component.getActionMap(); final Object oldActionKey = inputMap.get(enterKeyStroke); final Action oldAction = oldActionKey != null ? actionMap.get(oldActionKey) : null; inputMap.put(enterKeyStroke, "clickButton"); actionMap.put("clickButton", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (isOKActionEnabled()) { doOKAction(); } else if (oldAction != null) { oldAction.actionPerformed(e); } } }); }