1

I have no idea where to begin, I need to get the JLabel to be a clone of the JTextField as someone types into the JTextField.

I have no code on this so far as I have absolutely no clue on how to do code something that updates itself constantly.

Jad Chahine
  • 6,849
  • 8
  • 37
  • 59

2 Answers2

1

Check this

http://docs.oracle.com/javase/6/docs/api/javax/swing/event/DocumentListener.html

The DocumentListener should allow you receive updates from a changing JTextField.

I think you just need to override the changeUpdate method

for example :

Synchronize JTextFields Values by PropertyChangeListener

Community
  • 1
  • 1
Jad Chahine
  • 6,849
  • 8
  • 37
  • 59
1

You need do add a DocumentListener and update the JLabel whenever something was changed in the JTextField.

JLabel label = new JLabel();

JTextField tf = new JTextField();
tf.addDocumentListener(new DocumentListener) {
    @Override
    public void insertUpdate(DocumentEvent e) {
        label.setText(tf.getText());
    }
    //...
});
TheBass
  • 64
  • 1
  • 3