Search code examples
javaswingjtextfield

Is it possible to connect two JTextFields to edit both at once in real time


The problem is:

I have 2 JTextFields, 1 is input field and 2 is output. What I want to do is when type somethink to 1 field, that text will be coppied and modified to field 2. The problem is I would preffer to make changes in second field, while editting. I can do it after button click or accept of change but I want to do it in real time. I can guess I should use somekind of property listener?


Solution

  • with this post you can do it with documentlistener

    textField.getDocument().addDocumentListener(new DocumentListener() {
      public void changedUpdate(DocumentEvent e) {
        //do something
      }
      public void removeUpdate(DocumentEvent e) {
        //do something
      }
      public void insertUpdate(DocumentEvent e) {
       //do something
      }
    });