Here you can find the source of centerFrame(JFrame frame)
public static void centerFrame(JFrame frame)
//package com.java2s; import javax.swing.*; import java.awt.*; public class Main { public static void centerFrame(JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); frame.setLocation((screenSize.width / 2) - (frameSize.width / 2), (screenSize.height / 2) - (frameSize.height / 2)); }// w w w .j a v a 2 s. co m }