Here you can find the source of getCenterLocationAWT( final java.awt.Component comp, final boolean onTitleBarIfWindow)
private static int[] getCenterLocationAWT( final java.awt.Component comp, final boolean onTitleBarIfWindow) throws InterruptedException, InvocationTargetException
//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 }; } }