以编程方式关闭当前显示的 Java Swing JDialog 框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1301583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:02:15  来源:igfitidea点击:

Programatically closing currently displayed Java Swing JDialog box

javaswing

提问by Dave

Hi there I am working on an Java Swing application that performs a search on a database. It has 2 JDialogboxes that popup during the search.

您好,我正在开发一个对数据库执行搜索的 Java Swing 应用程序。它有 2 个JDialog在搜索过程中弹出的框。

The first tells the user that the search has started and has an OK button to close. The second tells the user that the search has returned and is also closed by hitting the OK button.

第一个告诉用户搜索已经开始并且有一个确定按钮可以关闭。第二个告诉用户搜索已经返回并且也通过点击 OK 按钮关闭。

I there a way of closing the first JDialogbox programatically, when the search returns, it's it will be pretty obvious that the seach was started by the time the search has returned.

我有一种以JDialog编程方式关闭第一个框的方法,当搜索返回时,很明显搜索在搜索返回时已开始。

回答by Eugene Ryzhikov

Even though closing dialog is as simple as calling setVisible(false)on it, I think your approach is not user intuitive. Showing two dialogs is a bad UI practice. What you have to do is to show progress animation/dialog. Once your search returns stop the progress animation/dialog and show the data returned. Here are some links about the subject:

尽管关闭对话框就像调用setVisible(false)它一样简单,但我认为您的方法不是用户直观的。显示两个对话框是一种糟糕的 UI 做法。您需要做的是显示进度动画/对话框。搜索返回后,停止进度动画/对话框并显示返回的数据。以下是有关该主题的一些链接:

http://java.sun.com/docs/books/tutorial/uiswing/components/progress.htmlhttp://developerlife.com/tutorials/?p=248

http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html http://developerlife.com/tutorials/?p=248

回答by nos

call the.dispose() method on the JDialog.

在 JDialog 上调用 the.dispose() 方法。