Here you can find the source of getCenterPosition(Dimension d)
Parameter | Description |
---|---|
d | Dimension object used (along with the size of the screen) to determine the center point location. |
public static Point getCenterPosition(Dimension d)
//package com.java2s; import java.awt.*; public class Main { /**/*w ww . j a v a2 s . c om*/ * Calculates x,y to center window of given dimension on the desktop * * @param d Dimension object used (along with the size of the screen) to determine the center point location. * * @return Point */ public static Point getCenterPosition(Dimension d) { Point retval = new Point(0, 0); try { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screen.width / 2) - (d.width / 2); int y = (screen.height / 2) - (d.height / 2); retval = new Point(x, y); } catch (Exception e) { retval = new Point(0, 0); } return retval; } }