JTextField () { JTextField nameEditorField = new JTextField(); nameEditorField.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { revertSchemeName(); cancelEdit(); } }, ESC_KEY_STROKE, JComponent.WHEN_FOCUSED); nameEditorField.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stopEdit(); } }, ENTER_KEY_STROKE, JComponent.WHEN_FOCUSED); nameEditorField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { stopEdit(); } }); nameEditorField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull DocumentEvent e) { validateOnTyping(); } }); return nameEditorField; }