Java Screen Center setWindowToScreenCenter(Window window)

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

Description

Move the specified window to the center of the screen.

License

Open Source License

Parameter

Parameter Description
window the specified window

Declaration

public static void setWindowToScreenCenter(Window window) 

Method Source Code

//package com.java2s;

import java.awt.Window;

public class Main {
    /**//from   w w w.  j a  v a  2  s  .  c  om
     * Move the specified window to the center of the screen. Cautious, it may
     * occupy two different screens if the system has two or more combined
     * screens.
     * 
     * @param window
     *            the specified window
     */
    public static void setWindowToScreenCenter(Window window) {
        int screenWidth = window.getToolkit().getScreenSize().width;
        int screenHeight = window.getToolkit().getScreenSize().height;
        window.setLocation(screenWidth / 2 - window.getSize().width / 2,
                screenHeight / 2 - window.getSize().height / 2);
    }
}

Related

  1. setLocationOnScreenToCenteredWithin(java.awt.Window window, java.awt.Component root)
  2. setLocationToCenter(Window window)
  3. setSizeAndCenterOnSreen(Window window, double widthFactor, double heightFactor)
  4. setupImage(BufferedImage image, int centerPos, int size, int maxSizePercentage)
  5. setWindowToCenterOfScreen(Window frm)