Here you can find the source of centerWindow(JDialog dialog)
public static void centerWindow(JDialog dialog)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JDialog; public class Main { public static void centerWindow(JFrame frame) { // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; }/*www . j av a2s .c om*/ if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } public static void centerWindow(JDialog dialog) { // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; } if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; } dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); } }