Monday, March 23, 2009

How do I display my Swing application in full screen mode?

The GraphicsDevice class has a method setFullScreenWindow() that allows you to specify the window to display in full screen mode on that device.


JFrame frame = new JFrame();

GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices =
environment.getScreenDevices();

// we will assume the screen of interest is the 1st one

GraphicDevice device = devices[0];
if (device.isFullScreenSupported())
{

// make frame undecorated and not resizeable

frame.setUndecorated(true);
frame.setResizable(false);

// go into full screen mode

device.setFullScreenWindow(frame);
frame.validate();
}

No comments: