void (JComponent component, Set<Pair<JComponent, Integer>> top, int limit) { try { Field clientProperties = JComponent.class.getDeclaredField("clientProperties"); clientProperties.setAccessible(true); Object o = clientProperties.get(component); if (o != null) { Method size = o.getClass().getMethod("size"); size.setAccessible(true); Object sizeResult = size.invoke(o); if (sizeResult instanceof Integer) { top.add(Pair.create(component, (Integer)sizeResult)); trimToLimit(top, limit); } } } catch (NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException e) { } for (int i = 0; i < component.getComponentCount(); i++) { Component child = component.getComponent(i); if (child instanceof JComponent) { checkClientProperties((JComponent)child, top, limit); } } }