Java tutorial
//package com.java2s; //License from project: Apache License import java.awt.*; public class Main { public static Point getScreenCenterLocation(Window w) { Dimension size = w.getSize(); Toolkit toolkit = Toolkit.getDefaultToolkit(); double desktopHeight = toolkit.getScreenSize().getHeight(); double desktopWidth = toolkit.getScreenSize().getWidth(); // To the left (hack for Ngoc's dual display) if (desktopWidth > 1600) { desktopWidth += 1600; } Point location = new Point(); location.x = (int) (desktopWidth - size.getWidth()) / 2; location.y = (int) (desktopHeight - size.getHeight()) / 2; return location; } }