Java Screen Center getCenteringPoint(Dimension size)

Here you can find the source of getCenteringPoint(Dimension size)

Description

Get the point on point on the screen at which to open a dialog or window for it to appear centered.

License

Open Source License

Parameter

Parameter Description
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.

Declaration

public static Point getCenteringPoint(Dimension size) 

Method Source Code

//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;
    }
}

Related

  1. getCenter(Component owner, Dimension size)
  2. getCenterCoordinates(Dimension d)
  3. getCenteredLocation(Component comp)
  4. getCenteredLocation(Window w)
  5. getCenteredLocation(Window window)
  6. getCenteringPoint(final Dimension frameDimension)
  7. getCenteringPointOnScreen(Dimension dimension)
  8. getCenterLocation(final Window frame)
  9. getCenterLocation(Window window)