- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个应用程序,我需要在框架上工作,同时我想打开一个对话框。
所以我将模态设置为 Dialog.ModalityType.MODELESS
。虽然这使我能够与父 JFrame 交互,但我无法再在对话框上使用 getValue()
。
这是一个正在运行的最小示例:
package Test;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class TestModalityDialog {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(800,600));
frame.setVisible(true);
frame.pack();
JOptionPane optionPane = new JOptionPane();
String[] options = new String[]{"Hello"};
JLabel label1 = new JLabel(
"Click on a cluster to delete it (needs to be confirmed by pressing the 'Confirm' button.");
JLabel label2 = new JLabel(
"Press 'p' to undelete an unconfirmed deletion.");
Object complexMsg[] = { label1, label2 };
optionPane.setMessage(complexMsg);
optionPane.setOptions(options);
optionPane.setMessageType(JOptionPane.PLAIN_MESSAGE);
JDialog dialog = optionPane.createDialog(frame,
"Select undesired clusters");
//dialog.setModalityType(Dialog.ModalityType.MODELESS); //uncomment this line out
dialog.setVisible(true);
dialog.setVisible(false);//must be set to false for Modality to work
dialog.setVisible(true);
Object obj = optionPane.getValue();
int result = -1;
for (int k = 0; k < options.length; k++) {
if (options[k].equals(obj)) {
result = k;
}
}
if (result == 0) {
System.out.println("Succesful");
}
}
}
当您按下标有“Hello”的按钮时,系统就会在这里工作。放在后面就无法与框架交互。如果取消注释
//dialog.setModalityType(Dialog.ModalityType.MODELESS);
这将允许“交互”(不是在这个最小的 ofc 示例中),但我不再使用系统了。
我没想到的第二件事是,在未注释的版本中,您必须按两次按钮才能工作。
如果需要帮助,我会很高兴,已经尝试了其他 3 个模态值,但没有成功。
干杯,佛
最佳答案
关于java - JDialog 的 Modality 设置为 Dialog.ModalityType.MODELESS : optionPane. getValue() 不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22540217/
如何在另一个 JDialog 中添加 JDialog? 最佳答案 JDialog secondDialog = new JDialog(this); // ("this" is the first J
我有一个 JDialog,其中有一个可打开新窗口的按钮。我想要做的是每当其他窗口打开时阻止此 JDialog。当我说阻止时,我的意思是用户无法操纵它,无法移动它或最大化或任何东西。 顺便问一下,对于带
我有一个从 JFrame 上的按钮打开的父 JDialog。父 JDialog 本身有一个从父对话框上的按钮打开的子 JDialog。当我关闭父对话框并使用框架上的按钮再次打开它时,我不希望子对话框也
抱歉这个奇怪的标题,但这是解释。所以我有一个带有学生列表的 StudentRepository 类,这些学生是在 GUI 上选择的(通过 TableModel)。学生对象的属性是: int stude
我有一个未修饰的模态 JDialog,当用户在模态对话框外单击时,我想将其设置为 setVisible(false)。 这在 Swing 中可能吗? 我正在做的是为日期选择器之类的文本字段弹出一个自定
我有一个模式设置对话框,它是一个 JDialog。在这个设置窗口中,我放置了一些组件,包括一个按钮到另一个模态设置对话框,它也是一个 JDialog。我制作了它们 JDialogs,因为这是我所知道的
我只想在单击 JDialog 之外时关闭 JDialog import javax.swing.JDialog; import javax.swing.JLabel; public class Dia
我正在尝试重现我在多个应用程序中看到的功能:我有一个带有多个 JDialog 的 GUI 应用程序。我想轻松地将它们紧密地组织在屏幕上:当我移动一个 JDialog,并且它的一个边界变得“接近”(例如
对 Java 相当陌生,并且遇到了 z 顺序问题。我有一个旧版 Java 应用程序,它有一个主窗口 A,它会弹出一个模式 JDialog B。单击 B 上的按钮后,会弹出一个模式对话框 C。 对于从
我的应用程序中有多个 JDialogs 存储在 map 中。这些JDialogs都有 setModel(false); 当这些对话框失去焦点并且我想将特定的 JDialog 带到前面时,所有 JDia
我有一个扩展 JDialog 的类。当 JDialog 显示时,我单击其启动 Jframe 的显示按钮,但在关闭 JDialog 之前我无法访问 JFrame。当屏幕上存在 JDialog 时,如何访
场景是这样的我的 JFrame 有一个按钮,单击它会打开一个 JDialog,它是一个模型对话框。JDialog 有另一个按钮,我想打开另一个 JFrmae 点击它打开。 结果:另一个 Jframe
我有一个带有主 JFrame 的小型应用程序,它以模态方式打开 JDialog。在这个 JDialog 中,我启动了一个 javax.swing.Timer,它应该在 JDialog 关闭时停止。 p
如何将用户凭据传回到包含的 JFrame,以便 JFrame 知道特定用户? JFrame 有一个 main 方法。 包含的 JFrame 能否以某种方式从 Dialog 中获取用户? 当jbtOk
我基本上创建的是一个 JDialog,它在表单上有一个关键事件。因此,当例如按下空间时,它会做一些事情。在我在同一个对话框上创建一个可编辑的 JTextArea 之前,这种方法工作得很好。当我这样做时
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我正在构建我的第一个 gui,到目前为止一切正常,除了 JDialog 的故障。 .它在第一次使用时相应地接受名称和进程列表。但是当我把它拉回来输入新的输入时,它仍然没有响应。我认为这不是线程问题,因
如何创建一个 Modal JDialog,在任务正在处理时显示“正在加载”,并在超过 3 秒后显示? 最佳答案 为了扩展 Paul 的回答,SwingWorker 可以很好地运行您的后台任务。然后您可
该程序大部分运行正常,但没有打开任何窗口。它应该在桌面右下角显示一个小对话框。但是对于另一个人来说,编译相同的代码没有问题。我们有相同的 Java 运行时 (1.8_u40)。我该如何解决这个问题?
我正在使用 Eclipse 的 Window Builder 插件。 当我执行以下代码时,它正确显示JDialog。我原本希望 JDialog 也能显示在设计选项卡中(在设计时),但它不会。 pack
我是一名优秀的程序员,十分优秀!