Center a window on the screen

From Stack Overflow
Jump to: navigation, search
     * Center a dialog box or window in the screen.  For example, in your constructor
     * or initializer, you can say
     *@param c Window, JWindow, Dialog, or JDialog to center
    public static void center(Window c)
        Dimension windowSize = c.getSize();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        c.setLocation(screenSize.width/2 - windowSize.width/2, screenSize.height/2 - windowSize.height/2);