Java JOptionPane.showConfirmDialog中的错误?
当用户想要关闭框架窗口时,我想提示用户确认,如下所示:Java JOptionPane.showConfirmDialog中的错误?,java,swing,joptionpane,Java,Swing,Joptionpane,当用户想要关闭框架窗口时,我想提示用户确认,如下所示: addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (JOptionPane.showConfirmDialog(null, "Are you sure you want to abort the game?", "Really quit?", JOptionPane
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();
}
});
对话框将显示,但无论单击“是”、“否”或“关闭窗口”,窗口都将关闭。这是某种bug还是我真的错过了一些简单的东西?我在OSX上使用Eclipse和Java1.6.0.13 您必须将框架设置为“关闭时不执行任何操作”,以控制关闭:
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
必须将框架设置为“关闭时不执行任何操作”才能控制关闭:
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);