运行以下示例后,活动窗口下会出现一个对话框窗口,例如,如果此时显示的活动时间比对话框活动的浏览器窗口。如何在系统中的所有窗口顶部显示对话框窗口?
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
JFrame frame = new JFrame("frame");
JOptionPane.showMessageDialog(
frame,
"test info",
"test header",
JOptionPane.INFORMATION_MESSAGE
);
使用
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
);
在框架声明下添加以下行
JFrame frame = new JFrame("frame");
frame.setAlwaysOnTop(true);
谢谢...