Here you can find the source of centerDialogInWindow(JDialog dialog, Window win)
public static void centerDialogInWindow(JDialog dialog, Window win)
//package com.java2s; /*/*from ww w .j av a 2 s . c o m*/ * funCKit - functional Circuit Kit * Copyright (C) 2013 Lukas Elsner <open@mindrunner.de> * Copyright (C) 2013 Peter Dahlberg <catdog2@tuxzone.org> * Copyright (C) 2013 Julian Stier <mail@julian-stier.de> * Copyright (C) 2013 Sebastian Vetter <mail@b4sti.eu> * Copyright (C) 2013 Thomas Poxrucker <poxrucker_t@web.de> * Copyright (C) 2013 Alexander Treml <alex.treml@directbox.com> * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ import javax.swing.JDialog; import java.awt.Window; public class Main { public static void centerDialogInWindow(JDialog dialog, Window win) { int posX = win.getLocation().x; int posY = win.getLocation().y; int dX = (win.getWidth() - dialog.getWidth()) / 2; int dY = (win.getHeight() - dialog.getHeight()) / 2; dialog.setLocation(posX + dX, posY + dY); } }