Component (JComponent parent, Point location) { int size = parent.getComponentCount(); for (int i = 0; i < size; i++) { Component child = parent.getComponent(i); if (child.isShowing()) { if (child.getWidth() < EMPTY_COMPONENT_SIZE || child.getHeight() < EMPTY_COMPONENT_SIZE) { Point childLocation = child.getLocationOnScreen(); Rectangle bounds = new Rectangle(); bounds.x = childLocation.x; bounds.y = childLocation.y; bounds.width = child.getWidth(); bounds.height = child.getHeight(); bounds.grow(child.getWidth() < EMPTY_COMPONENT_SIZE ? EMPTY_COMPONENT_SIZE : 0, child.getHeight() < EMPTY_COMPONENT_SIZE ? EMPTY_COMPONENT_SIZE : 0); if (bounds.contains(location)) { return child; } } if (child instanceof JComponent) { Component result = getDeepestEmptyComponentAt((JComponent)child, location); if (result != null) { return result; } } } } return null; }