Here you can find the source of centreOverFrame(JInternalFrame win, JInternalFrame parent)
win
over the internal frame parent
.
Parameter | Description |
---|---|
win | The JInternalFrame to position. |
parent | The reference JInternalFrame. |
public static void centreOverFrame(JInternalFrame win, JInternalFrame parent)
//package com.java2s; /*/*from w ww . ja v a2s . c o m*/ * Copyright (C) 2002-2014 FlyMine * * This code may be freely distributed and modified under the * terms of the GNU Lesser General Public Licence. This should * be distributed with the code. See the LICENSE file for more * information or http://www.gnu.org/copyleft/lesser.html. * */ import java.awt.Dimension; import java.awt.Rectangle; import javax.swing.JInternalFrame; public class Main { /** * Centre the internal frame <code>win</code> over the internal * frame <code>parent</code>. * * @param win The JInternalFrame to position. * @param parent The reference JInternalFrame. */ public static void centreOverFrame(JInternalFrame win, JInternalFrame parent) { Rectangle parentBounds = parent.getBounds(); Dimension windowSize = win.getSize(); int x = (parentBounds.width - windowSize.width) / 2; int y = (parentBounds.height - windowSize.height) / 2; x = Math.max(0, x + parentBounds.x); y = Math.max(0, y + parentBounds.y); win.setLocation(x, y); } }