Confirm Dialog
I want to get rid of the Cancel button in my confirm dialog, i tried commenting it out but that doesn't work.
int response = JOptionPane.showConfirmDialog(null,
"Do you want to clear everything?");
switch(response){
case JOptionPane.YES_OPTION:
textfield.setText("");
case JOptionPane.NO_OPTION:
//case JOptionPane.CANCEL_OPTION:
case JOptionPane.CLOSED_OPTION:
Thanks in advance :D
[721 byte] By [
kavon89a] at [2007-10-3 8:49:16]

int response = JOptionPane.showConfirmDialog(null, "Clear ALL clipped items?", "Confirm Deletion", JOptionPane.YES_NO_OPTION);
switch(response) {
case JOptionPane.YES_OPTION:
clippedtxt.clear();
case JOptionPane.NO_OPTION:
case JOptionPane.CLOSED_OPTION:
Works perfectly, thanks michael! New question. how do I add that same stuff above to the close button in the frame? This is what I currently have for my frame's default closing option:
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Would i just make a method with the above code for a confirm window and enter the method name into the parentheses of the frame.setDefault... line? If so, would i have JFrame.EXIT_ON_CLOSE as my YES_OPTION ?
you want to confirm closing of the app?
change
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
to
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
now add a windowListener
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
confirmDiaolg...
if(yes, close it) System.exit(0);
}
});
Thanks again!
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
int clickVALUE = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "Quit Confirmation", JOptionPane.YES_NO_OPTION);
if(clickVALUE == 0)
{
System.exit(0);
}
}
});
I did a little googling for the help on if(clickVALUE == 0) part. It's a shame my books don't have this stuff in them.