Here you can find the source of centerFrame(JFrame frame)
public static void centerFrame(JFrame frame)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; public class Main { public static void centerFrame(JFrame frame) { // Get the size of the screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); // Determine the new location of the window int w = frame.getSize().width; int h = frame.getSize().height; int x = (dim.width - w) / 2; int y = (dim.height - h) / 2; // Move the window frame.setLocation(x, y);/*w w w.ja v a 2 s.co m*/ } }