Java – Disabling a button in Netbeans GUI until correct password is put into the password field


I'm very new at coding, and I want a swing button in the netbeans GUI to stay disabled until the correct password is entered to a password field. I have already created the password field, and given it a correct password.

If you can keep it simple it would be appreciated, as I'm very new to programming in general.

Best Solution

You can make use of setEnabled property,


you can set it to false initially , upon validating make it true .

if (text.equals("password"))

As #setEnabled(boolean),

Enables or disables this component, depending on the value of the parameter b. An enabled component can respond to user input and generate events. Components are enabled initially by default.

Related Question