繁体   English   中英

JOptionPane.showConfirmDialog中的错误?

[英]Bug in JOptionPane.showConfirmDialog?

我想在用户想要关闭框架窗口时提示用户进行确认,例如:

addWindowListener(new WindowAdapter()
{
    public void windowClosing(WindowEvent e)
    {
        if (JOptionPane.showConfirmDialog(null, "Are you sure you want to abort the game?",
            "Really quit?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
        dispose();
    }
});

对话框出现,但是无论我单击是,否还是关闭窗口,窗口都会关闭。 这是某种错误还是我真的在这里缺少一些简单的东西? 我在OS X和Java 1.6.0.13上使用Eclipse。

您必须将框架设置为在关闭时不执行任何操作以控制关闭:

 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM