Here you can find the source of centreOnScreen(Window win)
Parameter | Description |
---|---|
win | The Window to position. |
public static void centreOnScreen(Window win)
//package com.java2s; /*//from w ww . ja v a 2s. c o m * Copyright (C) 2002-2014 FlyMine * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. See the LICENSE file for more * information or http://www.gnu.org/copyleft/lesser.html. * */ import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { /** * Centre the given window on the screen. * * @param win The Window to position. */ public static void centreOnScreen(Window win) { Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = win.getSize(); int x = Math.max(0, (screenRes.width - windowSize.width) / 2); int y = Math.max(0, (screenRes.height - windowSize.height) / 2); win.setLocation(x, y); } }