Here you can find the source of getFrameCenteredLocation(final java.awt.Component centerThis, final Component parent)
Parameter | Description |
---|---|
centerThis | a parameter |
public static java.awt.Point getFrameCenteredLocation(final java.awt.Component centerThis, final Component parent)
//package com.java2s; /*//w w w . jav a 2s .com * @(#) Helpers.java * * Created on 22.04.2006 by Daniel Becker (quippy@quippy.de) * *----------------------------------------------------------------------- * This program 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; either version 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *---------------------------------------------------------------------- */ import java.awt.Component; public class Main { /** * Get the location for centered Dialog * @since 22.06.2006 * @param centerThis * @return */ public static java.awt.Point getFrameCenteredLocation(final java.awt.Component centerThis, final Component parent) { java.awt.Dimension screenSize = (parent == null) ? java.awt.Toolkit.getDefaultToolkit().getScreenSize() : parent.getSize(); int x = (screenSize.width - centerThis.getWidth()) >> 1; int y = (screenSize.height - centerThis.getHeight()) >> 1; if (parent != null) { x += parent.getX(); y += parent.getY(); } if (x < 0) x = 0; if (y < 0) y = 0; return new java.awt.Point(x, y); } }