Here you can find the source of getCenteringPoint(Dimension size)
Parameter | Description |
---|---|
size | The demensions of the dialog or window to position. |
public static Point getCenteringPoint(Dimension size)
//package com.java2s; //License from project: Open Source License import java.awt.*; public class Main { /**/*from w w w . jav a 2 s .co m*/ * Get the point on point on the screen at which to open a dialog * or window for it to appear centered. This point is the top right hand * corner of the container you want to position. * * * @param size * The demensions of the dialog or window to position. * * @return * The top left hand point at which to position the container * for it to appear centered. * */ public static Point getCenteringPoint(Dimension size) { Point centeringPoint = new Point(); Dimension screenSize; screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (size.height > screenSize.height) { size.height = screenSize.height; } if (size.width > screenSize.width) { size.width = screenSize.width; } centeringPoint.x = (screenSize.width - size.width) / 2; centeringPoint.y = (screenSize.height - size.height) / 2; return centeringPoint; } }