Here you can find the source of centerDialog(JDialog dialog, JFrame parent)
static public void centerDialog(JDialog dialog, JFrame parent)
//package com.java2s; // it under the terms of the GNU General Public License as published by import javax.swing.*; import java.awt.*; public class Main { static public void centerDialog(JDialog dialog, JFrame parent) { Point p = parent.getLocationOnScreen(); p.x += ((parent.getWidth() - dialog.getWidth()) / 2); p.y += ((parent.getHeight() - dialog.getHeight()) / 2); if (p.y <= 0) p.y = 20;//from w w w .j av a 2 s .c o m if (p.x <= 0) p.x = 20; dialog.setLocation(p); } static public void centerDialog(JDialog dialog, JDialog parent) { Point p = parent.getLocationOnScreen(); p.x += ((parent.getWidth() - dialog.getWidth()) / 2); p.y += ((parent.getHeight() - dialog.getHeight()) / 2); if (p.y <= 0) p.y = 20; if (p.x <= 0) p.x = 20; dialog.setLocation(p); } }