Here you can find the source of setDialogCenter(JDialog frame)
public static void setDialogCenter(JDialog frame)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JDialog; public class Main { public static void setDialogCenter(JDialog frame) { Dimension screenSize = new Dimension(Toolkit.getDefaultToolkit().getScreenSize()); Dimension windowSize = new Dimension(frame.getPreferredSize()); int wdwLeft = screenSize.width / 2 - windowSize.width / 2; int wdwTop = screenSize.height / 2 - windowSize.height / 2; frame.pack();/*from w ww .ja v a 2 s . c o m*/ frame.setLocation(wdwLeft, wdwTop); } }