运行以下示例后,在活动窗口下会出现一个对话框窗口,例如,如果当前处于活动状态的浏览器窗口处于活动状态下方。如何在系统中的所有窗口顶部显示对话框窗口?
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
JFrame frame = new JFrame("frame");
JOptionPane.showMessageDialog(
frame,
"test info",
"test header",
JOptionPane.INFORMATION_MESSAGE
);
答案 0 :(得分:0)
使用
frame.setAlwaysOnTop(true);
在显示对话框之前..
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
JFrame frame = new JFrame("frame");
//it will keep this frame and its dialog always on top of the other frames/windows
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(
frame,
"test info",
"test header",
JOptionPane.INFORMATION_MESSAGE
);
答案 1 :(得分:0)
在框架声明
下添加以下行JFrame frame = new JFrame("frame");
frame.setAlwaysOnTop(true);
...谢谢