Daesos
Daesos

Reputation: 109

How to disable JButton without changing background on Netbeans

How can I disable a button without changing the colour of the background. When I press ready, the ready button and the blue button are disabled. But I want to keep the colour of the blue button. Could you help me? On the left the blue button, on the right the disabled buttons

Upvotes: 0

Views: 611

Answers (1)

Stultuske
Stultuske

Reputation: 9437

Easily: keep an instance variable 'isButtonEnabled', and instead of enabling or disabling the button, you change the value of this button.

Then, all you need to do:

public void actionPerformed(ActionEvent event){
  if ( isButtonEnabled){
    // the actual code
  }
}

Upvotes: 1

Related Questions