Here you can find the source of alignDialogInMiddleOfScreen(JDialog dlg)
private static void alignDialogInMiddleOfScreen(JDialog dlg)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.*; public class Main { private static void alignDialogInMiddleOfScreen(JDialog dlg) { Rectangle frameBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); int x = frameBounds.x + ((frameBounds.width - dlg.getSize().width) / 2); int y = frameBounds.y + ((frameBounds.height - dlg.getSize().height) / 2); dlg.setLocation(x, y);// w w w . j a va 2 s . co m } }