void (JComponent container) { List<PanelWithAnchor> panels = Arrays.stream(container.getComponents()) .filter(component -> component.isVisible()) .filter(component -> component instanceof PanelWithAnchor) .map(component -> (PanelWithAnchor)component) .collect(Collectors.toList()); UIUtil.mergeComponentsWithAnchor(panels, true); }