Here you can find the source of setFrameToMiddleOfTheScreen(Window window)
Parameter | Description |
---|---|
window | the window to be set |
public static void setFrameToMiddleOfTheScreen(Window window)
//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()); } }