Java tutorial
//package com.java2s; import java.awt.*; public class Main { public static void centerOnScreen(Window w) { centerOnScreen(w, null); } public static void centerOnScreen(Window w, Window parent) { Rectangle r = new Rectangle(); if (parent == null) { r.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } else { r.setLocation(parent.getLocation()); r.setSize(parent.getSize()); } // Determine the new location of the alert int x = r.x + (r.width - w.getWidth()) / 2; int y = r.y + (r.height - w.getHeight()) / 2; // Move the alert w.setLocation(x, y); } }