Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { public static final void centerOnScreen(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = window.getSize(); if (windowSize.height > screenSize.height) windowSize.height = screenSize.height; if (windowSize.width > screenSize.width) windowSize.width = screenSize.width; window.setLocation((screenSize.width - windowSize.width) / 2, (screenSize.height - windowSize.height) / 2); } }