[英]How to make swing dialog window on top?
After running the following example a dialog window appears under the active window, for example if a browser window active at the moment than dialog appears under it. 运行以下示例后,对话框窗口将出现在活动窗口下,例如,如果当前活动的浏览器窗口比对话框下出现。 How can I make dialog window appear on top of all windows in the system? 如何使对话框窗口出现在系统中所有窗口的顶部?
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
JFrame frame = new JFrame("frame");
JOptionPane.showMessageDialog(
frame,
"test info",
"test header",
JOptionPane.INFORMATION_MESSAGE
);
Use 采用
frame.setAlwaysOnTop(true);
before showing dialog.. 在显示对话框之前。
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
);
Add the following line under the frame declaration 在框架声明下添加以下行
JFrame frame = new JFrame("frame");
frame.setAlwaysOnTop(true);
Thanks... 谢谢...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.