Example usage for java.awt GraphicsDevice getDisplayMode

List of usage examples for java.awt GraphicsDevice getDisplayMode

Introduction

In this page you can find the example usage for java.awt GraphicsDevice getDisplayMode.

Prototype

public DisplayMode getDisplayMode() 

Source Link

Document

Returns the current display mode of this GraphicsDevice .

Usage

From source file:dylemator.DylematorUI.java

public void setFullscreen(boolean fullscreen) {
    //get a reference to the device.
    GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    DisplayMode dispMode = device.getDisplayMode();
    //save the old display mode before changing it.
    dispModeOld = device.getDisplayMode();

    if (this.fullscreen != fullscreen) { //are we actually changing modes.
                                         //change modes.
        this.fullscreen = fullscreen;
        // toggle fullscreen mode
        if (!fullscreen) {
            //change to windowed mode.
            //set the display mode back to the what it was when
            //the program was launched.
            device.setDisplayMode(dispModeOld);

            //hide the frame so we can change it.
            setVisible(false);/*from   w  ww  .  jav  a  2  s  . co m*/
            //remove the frame from being displayable.
            dispose();
            //put the borders back on the frame.
            setUndecorated(false);
            //needed to unset this window as the fullscreen window.
            device.setFullScreenWindow(null);
            //recenter window
            setLocationRelativeTo(null);
            setResizable(true);

            //reset the display mode to what it was before
            //we changed it.
            setVisible(true);

        } else { //change to fullscreen.
                 //hide everything
            setVisible(false);
            //remove the frame from being displayable.
            dispose();
            //remove borders around the frame
            setUndecorated(true);
            //make the window fullscreen.
            device.setFullScreenWindow(this);
            //attempt to change the screen resolution.
            device.setDisplayMode(dispMode);
            setResizable(false);
            setAlwaysOnTop(false);
            //show the frame
            setVisible(true);
        }
        //make sure that the screen is refreshed.
        repaint();

    }
    this.requestFocus();
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void initWindowPosition() {
    WindowState screenState = PreferencesManager.getSingleton().getScreenState();
    boolean boundsSet = false;
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (screenState != null) {
        setExtendedState(screenState.getExtendedState());
        int safety = 20;
        int screenWidth = gd.getDisplayMode().getWidth();
        int screenHeight = gd.getDisplayMode().getHeight();
        if (getExtendedState() == JFrame.NORMAL && screenState.getX() < (screenWidth - safety)
                && (screenState.getY() < screenHeight - safety && screenState.getWidth() <= screenWidth
                        && screenState.getHeight() <= screenHeight)) {
            boundsSet = true;// ww w .j  av  a  2s  . c  o m
            setBounds(screenState.getX(), screenState.getY(), screenState.getWidth(), screenState.getHeight());
        }
    }

    // make a fraction of the screen size by default
    if (!boundsSet && gd != null && getExtendedState() == JFrame.NORMAL) {
        int screenWidth = gd.getDisplayMode().getWidth();
        int screenHeight = gd.getDisplayMode().getHeight();
        setSize(3 * screenWidth / 4, 3 * screenHeight / 4);
    }
}