Java JDialog Center centerOn(JDialog dialog, Component other)

Here you can find the source of centerOn(JDialog dialog, Component other)

Description

center On

License

Open Source License

Declaration

public static void centerOn(JDialog dialog, Component other) 

Method Source Code


//package com.java2s;
/*/*ww w . j a  v  a2 s .  c om*/
 * 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.Component;

import java.awt.Rectangle;

import javax.swing.JDialog;

public class Main {
    public static void centerOn(JDialog dialog, Component other) {
        int w = dialog.getWidth();
        int h = dialog.getHeight();
        Rectangle bounds = other.getBounds();
        int bw = bounds.width;
        int bh = bounds.height;
        dialog.setLocation(bounds.x + (bw - w) / 2, bounds.y + (bh - h) / 2);
    }
}

Related

  1. centerDialog(JDialog dialog)
  2. centerDialog(JDialog dialog)
  3. centerDialog(JDialog dialog, Container parent)
  4. centerDialogInContainer(JDialog dialog, Container frame)
  5. centerDialogInWindow(JDialog dialog, Window win)
  6. centerOnComponent(JDialog dialog, Component comp)
  7. centerOnScreen(JDialog jdialog)
  8. centerWindow(JDialog dialog)
  9. centerWindow(JDialog dialog)