Here you can find the source of setWindowToScreenCenter(Window window)
Parameter | Description |
---|---|
window | the specified window |
public static void setWindowToScreenCenter(Window window)
//package com.java2s; import java.awt.Window; public class Main { /**//from w w w. j a v a 2 s . c om * Move the specified window to the center of the screen. Cautious, it may * occupy two different screens if the system has two or more combined * screens. * * @param window * the specified window */ public static void setWindowToScreenCenter(Window window) { int screenWidth = window.getToolkit().getScreenSize().width; int screenHeight = window.getToolkit().getScreenSize().height; window.setLocation(screenWidth / 2 - window.getSize().width / 2, screenHeight / 2 - window.getSize().height / 2); } }