简体   繁体   English

setDefaultCloseOperation在Swing中不起作用

[英]setDefaultCloseOperation not working in Swing

I need to stop the default operation of window being closed when red x mark is clicked on the swing window. 单击旋转窗口上的红色x标记时,我需要停止关闭窗口的默认操作。 I am using the JDialog and adding WindowsListener to it to capture the WindowClosing event, there I decide whether to dispose JDialog or to not dispose it, I am also setting the following: 我正在使用JDialog并向其中添加WindowsListener来捕获WindowClosing事件,在那里我决定是处置JDialog还是不处置JDialog,我还设置了以下内容:

setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

But still when I click on the red x mark, the window closes. 但是,当我单击红色的x标记时,窗口仍然关闭。 Any ideas? 有任何想法吗?

将Window侦听器添加到JDialog中使我能够处理窗口动作,并且在我的应用程序中运行良好。

You can try creating a WindowListener and do nothing when the close buttion is clicked. 您可以尝试创建WindowListener,而在单击关闭按钮时不执行任何操作。

jdialog.addWindowListener(new WindowAdapter() 
{
  public void windowClosed(WindowEvent e)
  {   
  }

  public void windowClosing(WindowEvent e)
  {
  }

});

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

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