Java Screen Center getCenterCoordinates(Dimension d)

Here you can find the source of getCenterCoordinates(Dimension d)

Description

get Center Coordinates

License

Open Source License

Return

the coordinates for the upper-left corner of you window so that it is centered

Declaration

public static Point getCenterCoordinates(Dimension d) 

Method Source Code


//package com.java2s;

import java.awt.Dimension;

import java.awt.Point;
import java.awt.Toolkit;

public class Main {
    /**/*from   w w  w .  j av  a2 s .c  o  m*/
     * @return the coordinates for the upper-left corner of you window
     * so that it is centered
     */
    public static Point getCenterCoordinates(Dimension d) {
        Dimension s = Toolkit.getDefaultToolkit().getScreenSize();

        Point ul = new Point();
        ul.x = (s.width - d.width) / 2;
        ul.y = (s.height - d.height) / 2;

        return (ul);
    }
}

Related

  1. centreOnScreen(Window frame)
  2. centreOnScreen(Window win)
  3. getCenter(Component owner, Dimension size)
  4. getCenteredLocation(Component comp)
  5. getCenteredLocation(Window w)
  6. getCenteredLocation(Window window)
  7. getCenteringPoint(Dimension size)