Java JFrame Center centerPosition(JFrame invokerFrame, Window w, int width, int height)

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

Description

center Position

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/**/* w  w w.j  a  va  2s.co  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. centerOnFrame(JDialog dialog, JFrame frame)
  2. centerOnFrame(JFrame frame, Component comp)
  3. centerOnParent(JDialog child, JFrame parent)
  4. centerOnScreen(JFrame frame, int screenID)
  5. centerPoint(int width, int height, JFrame frame)
  6. centerWindow(JFrame frame)
  7. centerWindow(JFrame frame)
  8. centerWindow(JFrame frame)
  9. centerWindow(JFrame window)