Java Screen Center getCenterLocation(Window window)

Here you can find the source of getCenterLocation(Window window)

Description

get Center Location

License

Open Source License

Declaration

public static Point getCenterLocation(Window window) 

Method Source Code


//package com.java2s;
/*//  ww  w.ja v a  2  s  .  c  o  m
 * 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 3 of the License, or
 * (at your option) any later version.
 */

import java.awt.*;

public class Main {
    public static Point getCenterLocation(Window window) {
        Dimension componentSize = window.getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Point pos = new Point();

        pos.x = ((screenSize.width / 2) - (componentSize.width / 2));
        pos.y = ((screenSize.height / 2) - (componentSize.height / 2)) - 30;
        return pos;
    }
}

Related

  1. getCenteredLocation(Window window)
  2. getCenteringPoint(Dimension size)
  3. getCenteringPoint(final Dimension frameDimension)
  4. getCenteringPointOnScreen(Dimension dimension)
  5. getCenterLocation(final Window frame)
  6. getCenterLocationAWT( final java.awt.Component comp, final boolean onTitleBarIfWindow)
  7. getCenterPoint()
  8. getCenterPoint(Component parent, Component comp)
  9. getCenterPoint(final int w, final int h)