Java tutorial
//package com.java2s; /* * Carrot2 project. * * Copyright (C) 2002-2006, Dawid Weiss, Stanisaw Osiski. * Portions (C) Contributors listed in "carrot2.CONTRIBUTORS" file. * All rights reserved. * * Refer to the full license file "carrot2.LICENSE" * in the root folder of the repository checkout or at: * http://www.carrot2.org/carrot2.LICENSE */ import java.awt.*; import javax.swing.*; public class Main { /** * Centers a {@link JFrame} on screen. */ public static void centerFrameOnScreen(JFrame frame) { final Dimension position = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((position.width - frame.getWidth()) / 2, (position.height - frame.getHeight()) / 2); } }