Here you can find the source of centerOnParent(JDialog child, JFrame parent)
Parameter | Description |
---|---|
child | a parameter |
parent | a parameter |
public static void centerOnParent(JDialog child, JFrame parent)
//package com.java2s; /******************************************************************************* * Copyright 2010 Olaf Sebelin/* w w w. ja v a2 s.co m*/ * * This file is part of Verdandi. * * Verdandi 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 3 of the License, or * (at your option) any later version. * * Verdandi 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 Verdandi. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import javax.swing.JDialog; import javax.swing.JFrame; public class Main { /** * Centers a Dialog on its parent frame; * * @param child * @param parent */ public static void centerOnParent(JDialog child, JFrame parent) { int posX = parent.getX() + (parent.getWidth() / 2) - (child.getWidth() / 2); int posY = parent.getY() + (parent.getHeight() / 2) - (child.getHeight() / 2); child.setBounds(posX, posY, child.getWidth(), child.getHeight()); } }