public static void enableFullscreen(final JFrame window, final boolean useExclusiveFullscreen) { window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if (appleEawtAvailable() && appleOSVersion() >= 7 && // lion and above javaVersion() >= 7) { // java 7 and above System.out.println("trying to apple fullscreen"); enableAppleFullscreen(window); } window.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_F11) { e.consume(); GraphicsDevice gd = getScreen(window); window.setVisible(false); // hide, so we can do stuff if (window.isUndecorated()) { // we are fullscreen, we should become unfullscreen window.setUndecorated(false); if (window.equals( gd.getFullScreenWindow())) { // we used exclusive mode to go fullscreen gd.setFullScreenWindow(null); } else { // we just got really big window.setExtendedState(JFrame.NORMAL); } } else { // we aren't fullscreen, we should become fullscreen if (javaVersion() >= 7) setAutoRequestFocus(window, true); window.setUndecorated(true); window.setBounds(gd.getDefaultConfiguration().getBounds()); if (useExclusiveFullscreen) { gd.setFullScreenWindow(window); } else { window.setExtendedState(JFrame.MAXIMIZED_BOTH); window.toFront(); } } window.pack(); window.setVisible(true); } } }); }