Java JFrame enterFullScreenIfPossible(JFrame mainAppFrame)

Here you can find the source of enterFullScreenIfPossible(JFrame mainAppFrame)

Description

enter Full Screen If Possible

License

BSD License

Parameter

Parameter Description
mainAppFrame window to be made full screen.

Declaration

public static void enterFullScreenIfPossible(JFrame mainAppFrame) 

Method Source Code

//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;
    }
}

Related

  1. displayWindow(final JFrame window)
  2. dispose(final JFrame frame)
  3. doDisableActiveRenderingInEDT(final JFrame jFrame)
  4. drawHelpPanel(String helpToDisplay, final JFrame frame)
  5. enable(final JFrame frame)
  6. error(JFrame frame, String msg)
  7. exitFullScreen(JFrame mainAppFrame)
  8. fileChooser(JFrame frame, boolean saveDialog, String windowName, String filterName, String filterExtension)
  9. findFileOpen(JFrame frame, String ext, String desc)