JComponent () { LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>(); labeledComponent.setText("Visitor class"); final JTextField nameField = new JTextField(visitorNameRef.get()); labeledComponent.setComponent(nameField); nameField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull final DocumentEvent e) { visitorNameRef.set(nameField.getText()); } }); return labeledComponent; }