Java Screen Center setWindowToCenterOfScreen(Window frm)

Here you can find the source of setWindowToCenterOfScreen(Window frm)

Description

set Window To Center Of Screen

License

Apache License

Declaration

public static void setWindowToCenterOfScreen(Window frm) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.Rectangle;
import java.awt.Window;

public class Main {
    public static void setWindowToCenterOfScreen(Window frm) {
        Rectangle screenBounds = frm.getGraphicsConfiguration().getBounds();

        int center_x = screenBounds.x + screenBounds.width / 2;
        int center_y = screenBounds.y + screenBounds.height / 2;

        frm.setLocation(center_x - frm.getWidth() / 2, center_y - frm.getHeight() / 2);
    }/*from  www.  j ava  2  s .c  om*/
}

Related

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