void () { DocumentListener documentAdapter = new DocumentAdapter() { @Override protected void textChanged(@NotNull DocumentEvent e) { checkValid(); } }; myLocationField.getTextField().getDocument().addDocumentListener(documentAdapter); Disposer.register(this, () -> myLocationField.getTextField().getDocument().removeDocumentListener(documentAdapter)); checkWebProjectValid(); }