Let ActionListener listen for change in JTextField instead of only enter?

后端 未结 3 2116
栀梦
栀梦 2020-12-04 01:27

So as you may know, if you have a text field and you add an ActionListener to it, it will only listen to the keypress of the enter button. However, I want to let my ActionLi

3条回答
  •  旧巷少年郎
    2020-12-04 02:03

    Yeah, but what is a document listener and how do you use it? You're not really answering the question.

    I have a JTextField in my app's user interface. When the user makes any change to it, I want a nearby JCheckBox to be checked. The purpose is to tell the app to USE the value that was entered. Users often enter a value there but if they don't explicitly tell the app to use it then the app continues to ignore it. Instead of "training" users I'm supposed to follow the principle of least astonishment and automatically check the "Use this value" box.

    But how do I listen for a change? Can't you guys just tell me the easy way, instead of "educating me" about document listeners?

提交回复
热议问题