Here you can find the source of centerWindow(JFrame window)
public static void centerWindow(JFrame window)
//package com.java2s; //License from project: Apache License import java.awt.*; import javax.swing.*; public class Main { public static void centerWindow(JFrame window) { //center window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = window.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; }/*from www . ja v a 2 s. c o m*/ if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } }