Java tutorial
//package com.java2s; /* * Copyright (c) 2014 tabletoptool.com team. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * rptools.com team - initial implementation * tabletoptool.com team - further development */ import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { public static void centerOnScreen(Window window) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension windowSize = window.getSize(); int x = (screenSize.width - windowSize.width) / 2; int y = (screenSize.height - windowSize.height) / 2; window.setLocation(x, y); } }