关闭所有Java子窗口 [英] Close all Java child windows

查看:73
本文介绍了关闭所有Java子窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java Swing中,是否可以找到并关闭当前正在显示的所有JDialog对象?

In Java Swing is there a way to find and close all JDialog objects currently being displayed?

我有一个大型应用程序,可以调用多个部分来显示一个对话框,但是我希望能够从单个角度检测并关闭该对话框.

I have a large application and there are multiple parts that can call to display a dialog but from one single point I want to be able to detect and close it.

推荐答案

保留对每个对话框(可能是集合中)的引用.需要时,迭代集合并调用dialog.setVisible(false).

Keep a reference to each of the dialogs (perhaps in a collection). When needed, iterate the collection and call dialog.setVisible(false).

按照@mKorbel的建议,您还可以使用:

As suggested by @mKorbel, you can also use:

Window[] windows = Window.getWindows();

在迭代数组并关闭内容时,您只需要检查父"窗口即可.

You'd just need to check for the 'parent' window when iterating the array and closing things.

这篇关于关闭所有Java子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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