void (@NotNull JTextComponent c) { ActionListener action = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { replace(); } }; c.registerKeyboardAction(action, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED); }