Here you can find the source of center(JDialog dialog)
public static void center(JDialog dialog)
//package com.java2s; import javax.swing.JFrame; import javax.swing.JDialog; import java.awt.Dimension; import java.awt.Toolkit; public class Main { /**/*from w ww .j av a2 s .c om*/ * 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); } }