2

I have a JFrame which I am setting to be full screen like so:

JFrame frame = new JFrame();
frame.setSize(1920, 1080); // Resolution of the monitor
frame.setUndecorated(true);
frame.setVisible(true);

Problem is, any popups (e.g. JDialogs) spawned from this frame open up behind the frame and I can only access them by alt-tabbing to them.

Furthermore, I am running a two monitor setup with each monitor treated as a separate display. If any windows are opened on top of the JFrame, and I move my mouse cursor to the second monitor, the windows disappear behind the JFrame. This is on RHEL 6.4, so perhaps it's a Linux window management issue? It should also be noted that I am running without gnome-panel, so it's a completely bare Linux desktop (no menu bar, no task bar).

Things behave normally when my JFrame is decorated. That is, pop ups open on top of it and windows no longer disappear behind it when I move my mouse cursor to the second monitor.

It's only when I set the JFrame to be undecorated and full screen that windows start getting lost behind it. It's like Linux is "locking" the undecorated JFrame to the monitor. I can't alt-drag it in this state either.

If I set the JFrame to be slightly smaller than the monitor resolution (e.g. 1 pixel smaller), then it is no longer "locked". I can alt-drag it and windows no longer get lost behind it.

Is there any way to prevent windows from getting lost behind the full screen, undecorated JFrame?

I've tried all solutions listed here, but none of them work: JFrame full screen focusing .

EDIT

The above problem happens when running under Java 7. Running under Java 8 fixes the dialog issue, but the screen crossing issue is still there.

Community
  • 1
  • 1
SilentByte
  • 1,098
  • 1
  • 10
  • 21

1 Answers1

0

Use the below code to solve the above mentioned issue

public static void setfullscreen(final JFrame frm)
    {
        frm.dispose();
        /**`enter code here`
         * Set the Frame as Undecorated
         */
        frm.setUndecorated(true);
        /**
         * set the Frame's resize property as false
         */
        frm.setResizable(false);

        frm.requestFocus();
        /**
         * sets the frame as visible
         */
        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                frm.setVisible(true);
            }

        }
        );

        Dimension screenSize = 
        Toolkit.getDefaultToolkit().getScreenSize();

        frm.setBounds(0,0,screenSize.width, screenSize.height);

    }

    /**
     * Close the Full Screen Mode 
     * @param frm
     */
    public static void closeFullScreen(final JFrame frm)
    {

        frm.dispose();

        frm.setUndecorated(false);
        /**
         * sets the frame as resize
         */
        frm.setResizable(true);
        /**
         * sets the frame as visible
         */

        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                frm.setVisible(true);
            }

        }
        );

    }

</i>