Java JDialog Center centerOnScreen(JDialog jdialog)

Here you can find the source of centerOnScreen(JDialog jdialog)

Description

center On Screen

License

Open Source License

Declaration

public static void centerOnScreen(JDialog jdialog) 

Method Source Code

//package com.java2s;
/*//  www  .j  a  va  2  s. co m
 * Copyright (c) 2009 Albert Kurucz. 
 *
 * This file, Util.java is part of JTStand.
 *
 * JTStand is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JTStand 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GTStand.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

import javax.swing.JDialog;

public class Main {
    public static void centerOnScreen(JDialog jdialog) {
        int w = jdialog.getWidth();
        int h = jdialog.getHeight();
        //        System.out.println("size: " + w + "," + h);

        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle bounds = env.getMaximumWindowBounds();
        int bw = bounds.width;
        int bh = bounds.height;
        //        System.out.println("max: " + bw + "," + bh);
        //        jdialog.setLocationByPlatform(false);
        jdialog.setLocation((bw - w) / 2, (bh - h) / 2);
    }
}

Related

  1. centerDialog(JDialog dialog, Container parent)
  2. centerDialogInContainer(JDialog dialog, Container frame)
  3. centerDialogInWindow(JDialog dialog, Window win)
  4. centerOn(JDialog dialog, Component other)
  5. centerOnComponent(JDialog dialog, Component comp)
  6. centerWindow(JDialog dialog)
  7. centerWindow(JDialog dialog)
  8. centrarVentana(JDialog pDialog)
  9. getCentralDialogLocation(Component parent, JDialog dialog)