Enable and disable JButton

0

I have two JButton in my window, btnCalcular and btnConfirmar . btnCalcular computes some values in the window, and btnConfirmar takes those values and stores them elsewhere. The issue is that obligatorily I want to leave btnConfirmar disabled while the other button is not clicked, so it does not save null values.

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

    
asked by anonymous 16.04.2016 / 17:10

1 answer

3

Start btnConfirmar in your window as disabled:

btnConfirmar.setEnabled(false);

Then, activate it within the actionPerformed of the other button, as needed:

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