Java Screen Center packAndCenter(Window window)

Here you can find the source of packAndCenter(Window window)

Description

packs a window and centers is onscreen

License

Open Source License

Parameter

Parameter Description
window the target window

Declaration

public static void packAndCenter(Window window) 

Method Source Code

//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);
    }
}

Related

  1. getPercentageOnScreen(Point location, Dimension size, Rectangle screen)
  2. locateOnScreenCenter(Component component)
  3. moveToCenter(Component componentToMove, Component componentToCenterOver)
  4. moveToScreenCenter(Window w)
  5. packAndCenter(Window wind)
  6. screenCenter(Window window)
  7. setCenter(Component comp)
  8. setCenter(Component comp, Component parent)
  9. setCenter(Component component)