Enable and disable Jbutton

Asked

Viewed 1,311 times

0

I have two JButton in my window, btnCalcular and btnConfirmar. The btnCalcular calculates some window values, and the btnConfirmar take these values and store them elsewhere. The point is that obligatorily I want to leave the btnConfirmar deactivated while the other button is not clicked, so it does not save null values.

I’ve tried the while (btnCalcular.getClickCount() > 0){...} but the IDE did not recognize, even though I put this condition within one of the methods of a MouseListener. How to do this ?

1 answer

3


Initiate the btnConfirmar in your window as disabled:

btnConfirmar.setEnabled(false);

Then activate it inside the actionPerformed from the other button as required:

    btnCalcular.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
             //ative ele assim que o botão for clicado
             btnConfirmar.setEnabled(true);             
        }
    });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.