Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; public class Main { public static void centerFrame(final Window frame) { final Rectangle bounds = frame.getBounds(); final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); bounds.x = (screen.width / 2) - (bounds.width / 2); bounds.y = (screen.height / 2) - (bounds.height / 2); frame.setBounds(bounds); } }