Here you can find the source of centerDialogInContainer(JDialog dialog, Container frame)
public static void centerDialogInContainer(JDialog dialog, Container frame)
//package com.java2s; import javax.swing.*; import java.awt.*; public class Main { public static void centerDialogInContainer(JDialog dialog, Container frame) { Dimension prefSize = dialog.getPreferredSize(); java.awt.Point parentLocation = frame.getLocationOnScreen(); Dimension parentSize = frame.getSize();//Toolkit.getDefaultToolkit().getScreenSize(); int x = parentLocation.x + (parentSize.width - prefSize.width) / 2; int y = parentLocation.y + (parentSize.height - prefSize.height) / 2; dialog.setLocation(x, y);// www.j a v a2s.c o m } }