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
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.