Dimension () { Dimension basicSize = super.getPreferredSize(); Icon icon = getIcon(); int position = horizontalTextPosition(); FontMetrics fm = getFontMetrics(getFont()); Rectangle viewRect = new Rectangle(0, 0, Short.MAX_VALUE, Short.MAX_VALUE); Insets insets = getInsets(); int dx = insets.left + insets.right; int dy = insets.top + insets.bottom; Rectangle iconR = new Rectangle(); Rectangle textR = new Rectangle(); SwingUtilities.layoutCompoundLabel(this, fm, getText(), icon, SwingConstants.CENTER, horizontalTextAlignment(), SwingConstants.CENTER, position, viewRect, iconR, textR, iconTextSpace()); int x1 = Math.min(iconR.x, textR.x); int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width); int y1 = Math.min(iconR.y, textR.y); int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height); Dimension rv = new Dimension(x2 - x1 + dx, y2 - y1 + dy); if (shallPaintDownArrow()) { rv.width += getDownArrowIcon().getIconWidth() + JBUI.scale(TEXT_ARROW_SPACE); } Insets m = getMargins(); JBInsets.addTo(rv, m); rv.width = Math.max(rv.width, basicSize.width); rv.height = Math.max(rv.height, basicSize.height); return rv; }