Java Window Center centerPosition(Window window, Window w, int width, int height)

Here you can find the source of centerPosition(Window window, Window w, int width, int height)

Description

center Position

License

Open Source License

Declaration

public static void centerPosition(Window window, Window w, int width, int height) 

Method Source Code

//package com.java2s;
/**/* w  w w  .  j  ava  2s.  c o  m*/
 * Copyright (C) 2005 Bruno Patini Furtado
 * 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 2 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, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Created on 09/10/2005 21:49:53
 */

import java.awt.Window;

import javax.swing.JFrame;

public class Main {
    public static void centerPosition(JFrame invokerFrame, Window w, int width, int height) {
        int x = invokerFrame.getX() + (invokerFrame.getWidth() - width) / 2;
        int y = invokerFrame.getY() + (invokerFrame.getHeight() - height) / 2;

        w.setBounds(x, y, width, height);
    }

    public static void centerPosition(Window window, Window w, int width, int height) {
        int x = window.getX() + (window.getWidth() - width) / 2;
        int y = window.getY() + (window.getHeight() - height) / 2;

        w.setBounds(x, y, width, height);
    }
}

Related

  1. centerOnParent(final Window child, final boolean absolute)
  2. centerWindow(Window w)
  3. packAndCenterWindow(Window dlg)
  4. packAndDisplayInCenterOfScreen(final Window f)
  5. positionCenterScreen(Window window)