Dimension () { Insets insets = button.getInsets(); Rectangle iconRectResult; // todo a strange logic that should be revised together with removeInsetsBeforeLayout // The following code looks more logical /* Rectangle rect = iconRect.union(textRect); JBInsets.addTo(rect, button.getInsets()); return new Dimension(rect.width, rect.height); */ if (removeInsetsBeforeLayout) { iconRectResult = iconRect.getBounds(); JBInsets.addTo(iconRectResult, insets); } else { iconRectResult = iconRect; } Rectangle textRectResult = textRect.getBounds(); JBInsets.addTo(textRectResult, insets); Rectangle rect = iconRectResult.union(textRectResult); return new Dimension(rect.width, rect.height); }