-2

Well, im saving reports but I've been having some trbs with the JCheckBox..

What i want to do is: When i click NO button, need no to save the file & unchecked the JCheckbox.

Due to everytime I press or click JCheckbox button actives the JOptionPane.

 private boolean saveReport(){

    String msg =    "<html><center>¿Desea Guardar el Archivo<br></center>" +
                    "<center>en el <b>Ordenador</b>?</br></center></html>" ; 

    JLabel label = new JLabel(msg);  
    label.setFont(new Font("verdana", Font.PLAIN, 13));

  if(this.guardar_Reporte.isEnabled()){
    JOptionPane.showConfirmDialog(this,label,"Guardar Archivo.",JOptionPane.YES_NO_OPTION);  

    return true;
  }

        if(JOptionPane.showConfirmDialog(this,label,"Guardar Archivo.",JOptionPane.YES_NO_OPTION)
                == JOptionPane.YES_OPTION){
                exportReports();
                return true;

        }
        if(JOptionPane.showConfirmDialog(this,label,"Guardar Archivo.",JOptionPane.YES_NO_OPTION)
                == JOptionPane.NO_OPTION){
            this.guardar_Reporte.setSelected(false);
             return true;

        }

        return false;

  }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
man
  • 35
  • 9

1 Answers1

2

I assume you have some kind of ActionListener or ChangeListerner attached to the JCheckBox, when the event is triggered, by the JCheckBox, you should check to see if it is selected by using JCheckBox#isSelected, when it returns true, call your save method

Check out How to Use Buttons, Check Boxes, and Radio Buttons for more details

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366