Java tutorial
//package com.java2s; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { public static void centerContainer(Window window) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = window.getSize(); int newWidth = (screen.width - size.width) / 2; int newHeight = (screen.height - size.height) / 2; window.setLocation(newWidth, newHeight); } }