Here you can find the source of centerWindowOnParent(Window w, JFrame parent)
public static void centerWindowOnParent(Window w, JFrame parent)
//package com.java2s; //License from project: LGPL import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Window; import javax.swing.JFrame; public class Main { public static void centerWindowOnParent(Window w, JFrame parent) { Rectangle bounds = parent.getBounds(); int cx = bounds.x + bounds.width / 2; int cy = bounds.y + bounds.height / 2; Dimension mySize = w.getSize(); w.setLocation(cx - mySize.width / 2, cy - mySize.height / 2); }/*from www. ja va 2 s.c o m*/ }