1

I want to make a pair JTextField/JLabel work as here on StackOverflow, I mean that I want a string to be displayed in JLabel as I write it in JTextField.

I tried adding ActionListener to JTextField but it works only for ENTER. Any ideas?

Robin92
  • 533
  • 1
  • 6
  • 20
  • 1
    @calderon: please delete your comment as it is most definitely the wrong approach (as mKorbel has already pointed out. Much better to use a DocumentListener as Joe (1+) suggests as this will capture copy-pastes as well. – Hovercraft Full Of Eels Nov 02 '12 at 20:08

1 Answers1

5

The DocumentListener should allow you receive updates from a changing text field. I think you just need to override the changeUpdate method. Good luck!

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

Joe
  • 366
  • 1
  • 6