int (int width, int height) { int count = getComponentCount(); for (int i = 0; i < count; i++) { Component component = getComponent(i); if (component.isVisible()) { Dimension size = component.getPreferredSize(); return component.getY() + component.getBaseline(size.width, size.height); } } return -1; }