Java JFrame Parent centreOverFrame(JInternalFrame win, JInternalFrame parent)

Here you can find the source of centreOverFrame(JInternalFrame win, JInternalFrame parent)

Description

Centre the internal frame win over the internal frame parent.

License

GNU General Public License

Parameter

Parameter Description
win The JInternalFrame to position.
parent The reference JInternalFrame.

Declaration

public static void centreOverFrame(JInternalFrame win, JInternalFrame parent) 

Method Source Code

//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);
    }
}

Related

  1. AllPlatformGetFile(String dialogTitle, File locationIn, final String fileExtension, FileFilter nonMacFileFilter, boolean allowMultipleSelect, JLayeredPane parentFrame)
  2. AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)
  3. AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter)
  4. buildParentFrame(Object inp)
  5. closeFrameWhenEscapePressed(final JRootPane panel, final ActionListener actListener)
  6. createExceptionDialog(Frame parent, String title, Throwable error)
  7. createProgressDialog(Frame parentFrame, String title, JProgressBar progressBar)
  8. enableAllComponents(final boolean enable, final Frame parent)