Java Screen Center getCenterLocationAWT( final java.awt.Component comp, final boolean onTitleBarIfWindow)

Here you can find the source of getCenterLocationAWT( final java.awt.Component comp, final boolean onTitleBarIfWindow)

Description

get Center Location AWT

License

Open Source License

Declaration

private static int[] getCenterLocationAWT(
            final java.awt.Component comp, final boolean onTitleBarIfWindow)
            throws InterruptedException, InvocationTargetException 

Method Source Code

//package com.java2s;

import java.lang.reflect.InvocationTargetException;

public class Main {
    private static int[] getCenterLocationAWT(
            final java.awt.Component comp, final boolean onTitleBarIfWindow)
            throws InterruptedException, InvocationTargetException {
        int x0, y0;
        final java.awt.Point p0 = comp.getLocationOnScreen();
        final java.awt.Rectangle r0 = comp.getBounds();
        if (onTitleBarIfWindow && comp instanceof java.awt.Window) {
            final java.awt.Window window = (java.awt.Window) comp;
            final java.awt.Insets insets = window.getInsets();
            y0 = (int) (p0.getY() + insets.top / 2.0 + .5);
        } else {//from  w w w. j  av a  2  s  .  com
            y0 = (int) (p0.getY() + r0.getHeight() / 2.0 + .5);
        }
        x0 = (int) (p0.getX() + r0.getWidth() / 2.0 + .5);
        return new int[] { x0, y0 };
    }
}

Related

  1. getCenteringPoint(Dimension size)
  2. getCenteringPoint(final Dimension frameDimension)
  3. getCenteringPointOnScreen(Dimension dimension)
  4. getCenterLocation(final Window frame)
  5. getCenterLocation(Window window)
  6. getCenterPoint()
  7. getCenterPoint(Component parent, Component comp)
  8. getCenterPoint(final int w, final int h)
  9. getCenterPointRelativeToScreen(Dimension size)