【发布时间】:2014-03-07 20:10:14
【问题描述】:
我有一个生成两个 JDialog 的 JFrame。三个窗口中的每一个都需要可聚焦(并且是我目前编写的方式),但是 JFrame 不会出现在对话框的顶部。当您单击任一对话框时,它们会彼此重叠弹出(如预期的那样),但 JFrame 只是拒绝出现在前面。
我需要它们保留 JDialogs(而不是 JFrames 本身),因为大多数当前行为都是可取的(即,当另一个窗口/应用程序阻塞任何或所有窗口时,如果您选择任何一个窗口,它们都会出现到前面(而三个 JFrame 会导致只有选定的一个出现)。
我的 JDialogs 构造函数是这样的:
SubDialog(JFrame parent /*, a handful, ofOther arguments */){
super(parent, ModalityType.MODELESS); //not even the modeless helped
setAlwaysOnTop(false); //not even the not always on top helped
setUndecorated(true); //maybe this has something to do with it (unlikely, just fyi)?
//some simple variable assignments
}
我什至尝试在我的 JFrame 中添加 setAlwaysOnTop(true)。没有骰子。我越来越绝望,甚至尝试了以下数字之一:
MyJFrame(String title){
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addWindowFocusListener(new WindowAdapter(){
public void windowGainedFocus(WindowEvent e){
final Window w = e.getWindow();
//PLEASE come to the front
w.toFront();
//even MOAR desperation
SwingUtilities.invokeLater(new Runnable(){
public void run(){
w.toFront(); //STILL no dice.
}
});
}
});
}
想法?我什么都没有。
【问题讨论】:
-
我认为您的意思是“ModalityType.MODELESS”,而不是“ModilityType.MODELESS”?另外,尝试调用 setModal(false);
-
糟糕。好眼力。拼写固定。设置 ModalityType.MODELESS 与调用 setModal(false) 相同。实际上,调用 setModal(false) 实际上会将模态类型更改为 MODELESS。反正我还是试过了,以防万一。没有骰子。
标签: java swing jdialog modality