Java tutorial
//package com.java2s; import java.awt.*; public class Main { public static Rectangle getRelativeBounds(Component component) { Rectangle bounds = new Rectangle(0, 0, component.getWidth(), component.getHeight()); Container parent = component.getParent(); while (parent != null) { bounds.x += component.getX(); bounds.y += component.getY(); component = parent; parent = component.getParent(); } return bounds; } }