Java Screen Full Size setFrameToMiddleOfTheScreen(Window window)

Here you can find the source of setFrameToMiddleOfTheScreen(Window window)

Description

Sets the given Window to the middle of the screen.

License

Open Source License

Parameter

Parameter Description
window the window to be set

Declaration

public static void setFrameToMiddleOfTheScreen(Window window) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2008 Stefan Franke                                           *
 *                                                                            *
 * This file is part of OpenVPN SysTray.                                      *
 *                                                                            *
 * OpenVPN SysTray is free software: you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by       *
 * the Free Software Foundation, version 2 of the License.                    *
 *                                                                            *
 * OpenVPN SysTray is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with OpenVPN SysTray.  If not, see <http://www.gnu.org/licenses/>.   *
 ******************************************************************************/

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;

public class Main {
    /**//  w ww .jav  a2 s.com
     * Sets the given {@link Window} to the middle of the screen.
     *
     * @param window the window to be set
     */
    public static void setFrameToMiddleOfTheScreen(Window window) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenMiddleX = screenSize.width / 2;
        int screenMiddleY = screenSize.height / 2;
        int x = screenMiddleX - (window.getWidth() / 2);
        int y = screenMiddleY - (window.getHeight() / 2);
        window.setBounds(x, y, window.getWidth(), window.getHeight());
    }
}

Related

  1. fullScreen(Window window)
  2. getOppositeFullScreenBoundsFor(Rectangle r, boolean includeReservedInsets)
  3. initializeScreenArea(int priority)
  4. locateInScreenCenter(Component c)
  5. locateOnOpticalScreenCenter(Component component)
  6. setWindowCanFullScreen(Window w, boolean flag)
  7. showOnSameScreenAsMouseCenter(Container frame)