Java tutorial
//package com.java2s; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.JDialog; import javax.swing.JFrame; public class Main { public static void centerFrame(JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); frame.setLocation((screenSize.width / 2) - (frameSize.width / 2), (screenSize.height / 2) - (frameSize.height / 2)); } public static void centerFrame(JDialog jd) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = jd.getSize(); jd.setLocation((screenSize.width / 2) - (frameSize.width / 2), (screenSize.height / 2) - (frameSize.height / 2)); } }