如何在顶部制作摇摆对话框窗口?

问题描述 投票:0回答:2

运行以下示例后,活动窗口下会出现一个对话框窗口,例如,如果此时显示的活动时间比对话框活动的浏览器窗口。如何在系统中的所有窗口顶部显示对话框窗口?

try {
    Thread.sleep(5000);
} catch (InterruptedException e) {
    e.printStackTrace();
}

JFrame frame = new JFrame("frame");
JOptionPane.showMessageDialog(
    frame,
    "test info",
    "test header",
    JOptionPane.INFORMATION_MESSAGE
);
java swing
2个回答
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
        );

0
投票

在框架声明下添加以下行

JFrame frame = new JFrame("frame");
frame.setAlwaysOnTop(true);         

谢谢...

© www.soinside.com 2019 - 2024. All rights reserved.