Java JDialog Center centerDialog(javax.swing.JDialog dialog)

Here you can find the source of centerDialog(javax.swing.JDialog dialog)

Description

Place a JDialog window to the center of computer screen.

License

Open Source License

Declaration

public static void centerDialog(javax.swing.JDialog dialog) 

Method Source Code

//package com.java2s;
/*//ww  w  . j ava2 s  .c o m
 * Copyright 2005 Ton Holsink
 *
 * This file is part of JSynthLib.
 *
 * JSynthLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or(at your option) any later version.
 *
 * JSynthLib is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JSynthLib; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

public class Main {
    /**
     * Place a JDialog window to the center of computer screen.
     */
    public static void centerDialog(javax.swing.JDialog dialog) {
        java.awt.Dimension screenSize = dialog.getToolkit().getScreenSize();
        java.awt.Dimension size = dialog.getSize();
        screenSize.height = screenSize.height / 2;
        screenSize.width = screenSize.width / 2;
        size.height = size.height / 2;
        size.width = size.width / 2;
        int y = screenSize.height - size.height;
        int x = screenSize.width - size.width;
        dialog.setLocation(x, y);
    }
}

Related

  1. center(JDialog dialog)
  2. center(JDialog frame)
  3. centerDialog(final JDialog target)
  4. centerDialog(JDialog dDialog)
  5. centerDialog(JDialog dialog)
  6. centerDialog(JDialog dialog)
  7. centerDialog(JDialog dialog, Container parent)