soapergem
soapergem

Reputation: 9989

How do I toggle a full screen Swing frame out of full screen mode?

I've got code that looks something like this, which makes my JFrame fullscreen:

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();

JFrame myFrame = new JFrame("Title", device);
myFrame.setVisible(true);
myFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); 
myFrame.setUndecorated(true);
myFrame.setResizable(false);
myFrame.validate();

device.setFullScreenWindow(myFrame);

How do I later get that same JFrame to stop being fullscreen and revert to being just a normal window? I don't see any opposite to the setFullScreenWindow method on the GraphicsDevice class. I'd like to be able to toggle back and forth as needed.

Upvotes: 2

Views: 3079

Answers (1)

jfdoming
jfdoming

Reputation: 975

Use setFullScreenWindow(null); and then call myFrame.setVisible(true);

Upvotes: 2

Related Questions