keep jButton grey until jTextFields != null

后端 未结 5 2006
暖寄归人
暖寄归人 2021-01-14 23:08

I have 4 jTextFields that I save the input to a file once a submit button is pressed. I want to be able to keep the submit button disabled until each field is at least not n

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 23:55

    You need to add listeners to detect when the user enters text. In order to have it register any change (and not just when the user hits Enter) you should attach a DocumentListener to the underlying document of each JTextField.

    Then, have each listener call a function to do your check and update the JButton's enabled status accordingly.

    Related

提交回复
热议问题