Here you can find the source of enterFullScreenIfPossible(JFrame mainAppFrame)
Parameter | Description |
---|---|
mainAppFrame | window to be made full screen. |
public static void enterFullScreenIfPossible(JFrame mainAppFrame)
//package com.java2s; /**//from w w w . j a va 2s .c o m * <p> * This class contains useful methods for positioning, sizing, and manipulating JFrames and other * Window-like elements. * </p> * <p> * <span class="BSDLicense"> This software is distributed under the <a * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>. </span> * </p> * * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu) */ import java.awt.*; import javax.swing.JFrame; public class Main { private static int cachedScreenHeight = 480; private static int cachedScreenWidth = 640; private static Point fsFrameLocation; private static boolean fsFrameResizable; private static Dimension fsFrameSize; private static boolean fsFrameUndecorated; /** * @param mainAppFrame * window to be made full screen. */ public static void enterFullScreenIfPossible(JFrame mainAppFrame) { final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); final GraphicsDevice defaultScreenDevice = ge.getDefaultScreenDevice(); // System.out.println(defaultScreenDevice.isFullScreenSupported()); // System.out.println(defaultScreenDevice.getDisplayMode()); // System.out.println(defaultScreenDevice.getDisplayMode().getWidth()); // System.out.println(defaultScreenDevice.getDisplayMode().getHeight()); // System.out.println(defaultScreenDevice.getDisplayMode() // .getRefreshRate()); // System.out.println(defaultScreenDevice.getDisplayMode().getBitDepth()); if (defaultScreenDevice.isFullScreenSupported()) { try { mainAppFrame.dispose(); fsFrameSize = mainAppFrame.getSize(); mainAppFrame.setSize(getScreenSize()); fsFrameUndecorated = mainAppFrame.isUndecorated(); mainAppFrame.setUndecorated(true); fsFrameResizable = mainAppFrame.isResizable(); mainAppFrame.setResizable(false); fsFrameLocation = mainAppFrame.getLocation(); mainAppFrame.setLocation(0, 0); defaultScreenDevice.setFullScreenWindow(mainAppFrame); } finally { defaultScreenDevice.setFullScreenWindow(null); } } else { System.err.println("Fullscreen mode is not supported on this monitor."); } } /** * @return the screen size of the last known monitor mode */ public static Dimension getScreenSize() { return new Dimension(getScreenWidth(), getScreenHeight()); } /** * @return */ public static int getScreenWidth() { return cachedScreenWidth; } /** * @return */ public static int getScreenHeight() { return cachedScreenHeight; } }