javaswingjframewindowwindow-decoration

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


I have a little JFrame that should not appear in the taskbar and that should be undecorated. I achieved it with this code, but the Frame is not displaying any content.

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

When I replace

instance.setType(JFrame.Type.POPUP); with

instance.setType(JFrame.Type.UTILITY);

it shows the content again, but also shows the Frame in the taskbar.

Thanks in advance! Simon


Solution

  • If you want your frame to be undecorated as well as not visible in desktop you can use JWindow.It has all the functionality similar to JFrame so replace your JFrame with 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.

    Sample JWindow code

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