Dimension (List<? extends Component> list) { int gap = myGap.get(); Dimension result = null; for (Component component : list) { if (component.isVisible()) { result = join(result, gap, LayoutUtil.getPreferredSize(component)); } } return result; }