Reputation: 41
Following is my swing program code
import javax.swing.*;
import java.awt.event.*;
public class OptionPaneExample extends WindowAdapter{
JFrame f;
OptionPaneExample(){
f=new JFrame();
f.addWindowListener(this);
f.setSize(300, 300);
f.setLayout(null);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.setVisible(true);
}
public void windowClosing(WindowEvent e) {
int a=JOptionPane.showConfirmDialog(f,"Are you sure?");
if(a==JOptionPane.YES_OPTION){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public static void main(String[] args) {
new OptionPaneExample();
}
}
In output i want only two buttons Yes and No. But in output i'm getting cancel button. How to remove that please let me know.
I'm getting this output. But i want only two buttons Yes and No.
Upvotes: 3
Views: 4837
Reputation: 2981
int a=JOptionPane.showConfirmDialog(f,"Are you sure?", "Question", YES_NO_OPTION );
Please read the documentation for JOptionPane
.
Upvotes: 2
Reputation: 102
Try:
int a = JOptionPane.showConfirmDialog(f, "Your Message", "Title on Box", JOptionPane.YES_NO_OPTION);
Upvotes: 1