【发布时间】:2018-06-06 16:48:06
【问题描述】:
我想在buttonGroup 未激活且单击搜索按钮时打开包含错误消息的DialogFrame。所以在 ActionEvent 中,我将DialogFrame 设置为setVisible(true)。但是当按钮组处于活动状态并且我单击搜索按钮(在if 条件内)时,setVisible(false) 似乎不起作用,换句话说,DialogFrame 仍然弹出!
如何在if 条件内关闭DialogFrame 的可见性?
private void jButtonSearchActionPerformed(java.awt.event.ActionEvent evt) {
SrchEMsg sem = new SrchEMsg(this);
sem.setVisible(true);
sem.setLocationRelativeTo(null);
sem.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
if (bgGroup.getSelection() != null) {
sem.setVisible(false); //doesn't work.
SrchResult sr = new SrchResult();
sr.setVisible(true);
sr.pack();
sr.setLocationRelativeTo(null);
sr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.dispose();
}
}
【问题讨论】:
-
JDialog 是模态的吗?如果是这样,那么它将在设置为可见后阻塞代码流。
-
为什么默认设置为可见?为什么不
sem.setVisible(bgGroup.getSelection() == null); -
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2)对问题使用相关标签。
JDialog标签是相关的,你的 IDE 的标签不相关。
标签: java swing visibility jdialog