【问题标题】:Bug in JOptionPane.showConfirmDialog?JOptionPane.showConfirmDialog 中的错误?
【发布时间】:2023-03-23 01:30:02
【问题描述】:

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

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();
    }
});

对话框显示,但无论我单击是、否还是关闭窗口,窗口都会关闭。这是某种错误还是我真的在这里错过了一些简单的东西?我在带有 Java 1.6.0.13 的 OS X 上使用 Eclipse。

【问题讨论】:

    标签: java swing joptionpane


    【解决方案1】:

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

     setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-31
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      相关资源
      最近更新 更多