当 JFrame.setType 设置为 Type.POPUP 时 JFrame 停止显示内容

JFrame stops showing content when JFrame.setType is set to Type.POPUP

我有一个小的 JFrame,它不应该出现在任务栏中并且应该是未修饰的。 我用这段代码实现了,但是框架没有显示任何内容。

super();
instance = this;
instance.setUndecorated(true);
instance.setType(JFrame.Type.POPUP);

当我替换

instance.setType(JFrame.Type.POPUP);

instance.setType(JFrame.Type.UTILITY);

它再次显示内容,但也显示任务栏中的框架。

提前致谢! 西蒙

如果您希望您的框架不被修饰并且在桌面上不可见,您可以使用 JWindow。它具有与 JFrame 类似的所有功能,因此请将您的 JFrame 替换为JWindow

A JWindow is a container that can be displayed anywhere on the user's desktop. It does not have the title bar, window-management buttons, or other trimmings associated with a JFrame, but it is still a "first-class citizen" of the user's desktop, and can exist anywhere on it.

示例 JWindow 代码

   JWindow window = new JWindow();
    window.add(new JButton("test"));
    window.setSize(500, 500);
    window.setLocationRelativeTo(null);
    window.setVisible(true);