Java JDialog Center getCentralDialogLocation(Component parent, JDialog dialog)

Here you can find the source of getCentralDialogLocation(Component parent, JDialog dialog)

Description

get Central Dialog Location

License

Mozilla Public License

Declaration

public static Point getCentralDialogLocation(Component parent, JDialog dialog) 

Method Source Code


//package com.java2s;
/*//from  w  ww  .  j  a v  a 2  s.  c o  m
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Code is Knowtator.
 *
 * The Initial Developer of the Original Code is University of Colorado.  
 * Copyright (C) 2005-2008.  All Rights Reserved.
 *
 * Knowtator was developed by the Center for Computational Pharmacology
 * (http://compbio.uchcs.edu) at the University of Colorado Health 
 *  Sciences Center School of Medicine with support from the National 
 *  Library of Medicine.  
 *
 * Current information about Knowtator can be obtained at 
 * http://knowtator.sourceforge.net/
 *
 * Contributor(s):
 *   Philip V. Ogren <philip@ogren.info> (Original Author)
 */

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JDialog;

public class Main {
    public static Point getCentralDialogLocation(Component parent, JDialog dialog) {
        Point parentLocation = parent.getLocation();
        Dimension parentSize = parent.getSize();

        Dimension dialogSize = dialog.getSize();

        int x = Math.max(0, parentLocation.x + parentSize.width / 2 - dialogSize.width / 2);
        int y = Math.max(0, parentLocation.y + parentSize.height / 2 - dialogSize.height / 2);

        return new Point(x, y);
    }
}

Related

  1. centerOnComponent(JDialog dialog, Component comp)
  2. centerOnScreen(JDialog jdialog)
  3. centerWindow(JDialog dialog)
  4. centerWindow(JDialog dialog)
  5. centrarVentana(JDialog pDialog)
  6. getCentredDialogBounds(JDialog dialog, Component parent, int defaultWidth, int defaultHeight)
  7. packAndCenterJDialog(JDialog form)
  8. packInCenter(JDialog dialog)
  9. resizeAndCenter(JDialog dialog, double factor)