void (JComponent component, Set<Pair<JComponent, Integer>> top, int limit) { top.add(Pair.create(component, component.getComponentCount())); trimToLimit(top, limit); for (int i = 0; i < component.getComponentCount(); i++) { Component child = component.getComponent(i); if (child instanceof JComponent) { checkParents((JComponent)child, top, limit); } } }