Dimension (Container container) { Dimension size = JBUI.emptySize(); for (Pair<Component, String> c : actionButtons) { if (c.first.isVisible()) { Dimension prefSize = c.first.getPreferredSize(); size.height = Math.max(size.height, prefSize.height); } } for (Pair<Component, String> c : actionButtons) { if (c.first.isVisible()) { Dimension prefSize = c.first.getPreferredSize(); Insets i = ((JComponent)c.first).getInsets(); JBInsets.removeFrom(prefSize, i); if (ActionToolbar.SEPARATOR_CONSTRAINT.equals(c.second)) { size.width += prefSize.width + i.left + i.right; } else { int maxBareHeight = size.height - i.top - i.bottom; size.width += Math.max(prefSize.width, maxBareHeight) + i.left + i.right; } } } if (size.width > 0 && size.height > 0) { JBInsets.addTo(size, container.getInsets()); } return size; }