[英]Modal dialog not always on top of an undecorated JFrame when another JFrame is visible
I have a weird problem with modal dialogs and undecorated JFrame
. 模态对话框和未修饰的JFrame
有一个奇怪的问题。
If I create a main undecorated JFrame
then I display a modal dialog thanks to the JOptionPane
, everything goes well. 如果我创建一个主要的未修饰的JFrame
那么我会通过JOptionPane
显示一个模态对话框,一切顺利。 The modal dialog stays always on top and I can't click on the main fame. 模态对话框始终位于顶部,我无法点击主要名声。
But, if create another JFrame
(or another JDialog
), the modal dialog still prevent me to interact with the main frame, but now the modal dialog is not always on top and go underneath the main frame when I click on it. 但是,如果创建另一个JFrame
(或另一个JDialog
),模态对话框仍然阻止我与主框架交互,但现在模式对话框并不总是在顶部,当我点击它时在主框架下面。
This problem doesn't happen: 这个问题不会发生:
EDIT 编辑
I use jdk1.7.0.0_09
on Linux Sus
e.But I have the same result with jre 1.6.0_32
我在Linux Sus
上使用jdk1.7.0.0_09
但是我和jre 1.6.0_32
结果相同
The code I used to test: 我用来测试的代码:
public static void main(String[] args) {
// creates main frame and set visible to true
final JFrame mainFrame = new JFrame();
mainFrame.setUndecorated(true); // if I comment this line, everything goes well
mainFrame.add((new JPanel()).add(new JButton("OK")));
mainFrame.setSize(new Dimension(500, 500));
mainFrame.setVisible(true);
// creates a dialog and set visible to true
JFrame anotherFrame = new JFrame();
anotherFrame.setVisible(true); // or if I comment this line, everything goes well too
// display a modal dialog
JOptionPane.showMessageDialog(mainFrame, "A message");
}
But, if create another JFrame (or another JDialog), the modal dialog still prevent me to interact with the main frame, but now the modal dialog is not always on top and go underneath the main frame when I click on it. 但是,如果创建另一个JFrame(或另一个JDialog),模态对话框仍然阻止我与主框架交互,但现在模式对话框并不总是在顶部,当我点击它时在主框架下面。
not true at all, both are not accesible untill JOptioPane is visible 根本不是真的,两者都不可访问,直到JOptioPane可见
JOptionPane or JDialod.setModal(true) block mouse or key events to the alll windows invoked from currnet JVM JOptionPane或JDialod.setModal(true)阻止从currnet JVM调用的alll窗口的鼠标或键事件
there must be something else that isn't clear from your question, rest of code, minor could be Java version and Native OS 必须有一些其他东西从你的问题不清楚,其余的代码,次要可能是Java版本和本机操作系统
code for Java6 (winxp), works for me on Win7 / Java7(x.x_011) Java6(winxp)的代码,适用于Win7 / Java7(x.x_011)
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Main {
private JFrame mainFrame = new JFrame();
private JFrame anotherFrame = new JFrame();
public Main() {
mainFrame.setUndecorated(true);
mainFrame.add((new JPanel()).add(new JButton("OK")));
mainFrame.setSize(new Dimension(100, 60));
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
anotherFrame.setVisible(true);
anotherFrame.setLocation(110, 0);
anotherFrame.setSize(new Dimension(100, 60));
anotherFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JOptionPane.showMessageDialog(mainFrame, "A message");
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Main main = new Main();
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.