How to call setUndecorated() after a frame is made visible?

前端 未结 7 1817
醉梦人生
醉梦人生 2020-11-30 10:52

In my Swing application, I want the ability to switch between decorated and undecorated without recreating the entire frame. However, the API doesn\'t let me call setU

7条回答
  •  爱一瞬间的悲伤
    2020-11-30 11:43

    Have a look at https://tvbrowser.svn.sourceforge.net/svnroot/tvbrowser/trunk/tvbrowser/src/tvbrowser/ui/mainframe/MainFrame.java

    In Method switchFullscreenMode():

    dispose();
    ...
    setFullScreenWindow(...);
    setUndecorated(true/false);
    setBounds(mXPos, mYPos, mWidth, mHeight);
    ...
    setVisible(true);
    

    Actually there's a lot more stuff going on to hide various sidepanels that reappear if the mouse touches the sides.

    Also note that you must explicitly set the bounds. Window.setExtendedState(MAXIMIZED_BOTH) interferes badly in timely vicinity of dispose(), because they both rely on multiple native events of the operating system, that are lost, should the window no be displayable at that split second.

    I don't recommend taking the default screen directly:

    GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    

    and instead use the Screen, your JFrame is currently on:

    setBounds(getGraphicsConfiguration().getBounds());
    getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
    

    Though it's currently the same, it might change in the future.

提交回复
热议问题