Java tutorial
//package com.java2s; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { public static void center(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = window.getSize(); frameSize.height = ((frameSize.height > screenSize.height) ? screenSize.height : frameSize.height); frameSize.width = ((frameSize.width > screenSize.width) ? screenSize.width : frameSize.width); window.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } }