setDefaultCloseOperation在Swing中不起作用 [英] setDefaultCloseOperation not working in Swing

查看:61
本文介绍了setDefaultCloseOperation在Swing中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击旋转窗口上的红色x标记时,我需要停止关闭窗口的默认操作.我正在使用JDialog并向其中添加WindowsListener来捕获WindowClosing事件,在那里我决定是处置JDialog还是不处置JDialog,我还设置了以下内容:

I need to stop the default operation of window being closed when red x mark is clicked on the swing window. 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:

setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

但是,当我单击红色的x标记时,窗口仍然关闭.有什么想法吗?

But still when I click on the red x mark, the window closes. Any ideas?

推荐答案

向JDialog添加窗口侦听器使我能够处理窗口操作,并且在我的应用程序中运行良好.

Adding Window listener to the JDialog gave me the power to handle the window actions and I works fine in my application.

这篇关于setDefaultCloseOperation在Swing中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆