Java JFrame Center centerWindowOnParent(Window w, JFrame parent)

Here you can find the source of centerWindowOnParent(Window w, JFrame parent)

Description

center Window On Parent

License

LGPL

Declaration

public static void centerWindowOnParent(Window w, JFrame parent) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Dimension;
import java.awt.Rectangle;

import java.awt.Window;
import javax.swing.JFrame;

public class Main {
    public static void centerWindowOnParent(Window w, JFrame parent) {
        Rectangle bounds = parent.getBounds();
        int cx = bounds.x + bounds.width / 2;
        int cy = bounds.y + bounds.height / 2;
        Dimension mySize = w.getSize();
        w.setLocation(cx - mySize.width / 2, cy - mySize.height / 2);
    }/*from  www. ja  va 2 s.c  o m*/
}

Related

  1. centerWindow(JFrame frame)
  2. centerWindow(JFrame frame)
  3. centerWindow(JFrame frame)
  4. centerWindow(JFrame window)
  5. centerWindowInFrame(Component window, Window frame)
  6. centerWithinDesktop(JInternalFrame frame)
  7. createCenteredJFrame(String title, int width, int height, boolean autoclose)
  8. getCenteringFrame()
  9. getCenterOfTheWindow(JFrame frame)