Search code examples
javaswingdynamicjlabeljtextfield

Dynamic/Onspot JTextfield to JLabel


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?


Solution

  • 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