this.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
int par1 = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit", "Exit?", JOptionPane.YES_NO_OPTION);
if(par1==JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
});
这是我的代码。如何在 JOptionPane requestFocus 中设置“否”按钮?
最佳答案
使用JOptionPane.showOptionDialog并设置 options
和 initialValue
参数。
public static int showOptionDialog(Component parentComponent,
Object message,
String title,
int optionType,
int messageType,
Icon icon,
Object[] options,
Object initialValue)
throws HeadlessException
试试这个:
Object[] options = { "YES", "NO" };
int par1 = JOptionPane.showOptionDialog(null, "Are you sure you want to exit", "Exit?",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[1]);
if(par1==0)
{
System.exit(0);
}
更多 JOptionPane
关于Java - 关于 JOptionPane 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15458870/