Here you can find the source of positionCenterScreen(Window window)
public static void positionCenterScreen(Window window)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.*; public class Main { public static void positionCenterScreen(Window window) { Dimension maxDimension = Toolkit.getDefaultToolkit().getScreenSize(); Dimension wSize = window.getSize(); int maxWidth = maxDimension.width; int maxHeight = maxDimension.height; // fit on window if (wSize.height > maxHeight) { wSize.height = maxHeight;/* w w w . j a va2 s. c o m*/ } if (wSize.width > maxWidth) { wSize.width = maxWidth; } window.setSize(wSize); if (maxDimension.width != wSize.width && maxDimension.height != wSize.height) { int x = (maxDimension.width - wSize.width) / 2; int y = (maxDimension.height - wSize.height) / 2; window.setLocation(x, y); } else { if (window instanceof JFrame) { JFrame f = (JFrame) window; f.setExtendedState(JFrame.MAXIMIZED_BOTH); } else { window.setLocation(0, 0); } } window.toFront(); } }