Here you can find the source of packAndCenter(Window window)
Parameter | Description |
---|---|
window | the target window |
public static void packAndCenter(Window window)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class Main { /**// www . j av a 2s . com * packs a window and centers is onscreen * @param window the target window */ public static void packAndCenter(Window window) { window.pack(); Dimension size = window.getSize(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation((screen.width - size.width) / 2, (screen.height - size.height) / 2); } }