Skip to main content

Fullscreen mode is cool

Posted by mkarg on January 3, 2010 at 7:13 AM PST

Just found out how easy it is to use the full screen mode in Swing and certainly immediately must write down this blog entry. Using the full screen mode is just as easy as the sample shows:

 public final class FullscreenSample {

public static final void main(final String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

final JFrame fullscreenFrame = new JFrame();
fullscreenFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
fullscreenFrame.setUndecorated(true);
fullscreenFrame.setResizable(false);
fullscreenFrame.add(new JLabel("Press ALT+F4 to exit fullscreen.", SwingConstants.CENTER), BorderLayout.CENTER);
fullscreenFrame.validate();

GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(fullscreenFrame);
}

}

Running this program you will notice that the only thing you see is the empty frame (with the label). You see no other windows, no title bar, no system menu, no minimize / maximize / close buttons, no window borders, nothing, just the frame! And: YES, YOU DO NOT SEE THE TASK BAR ANYMORE!

As you can see, there is no magic. Just tell the screen device (i. e. the monitor that you want to set to full screen mode) that it shall be in full screen mode. That's it. :-)