Here you can find the source of center(JFrame frame)
public static void center(JFrame frame)
//package com.java2s; import javax.swing.JFrame; import javax.swing.JDialog; import java.awt.Dimension; import java.awt.Toolkit; public class Main { /**//from www . ja v a 2 s.com * Center JFrame. */ public static void center(JFrame frame) { Dimension frameSize = frame.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1); } /** * Center JDialog. */ public static void center(JDialog dialog) { Dimension dialogSize = dialog.getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); dialog.setLocation((screenSize.width - dialogSize.width) >> 1, (screenSize.height - dialogSize.height) >> 1); } }