Dimension (Insets labelInsets) { String caption = getCaption(); if (caption == null) { return new Dimension(Math.max(myPrefWidth, 0), 1); } FontMetrics fm = getFontMetrics(getFont()); int width = myPrefWidth < 0 ? fm.stringWidth(caption) + labelInsets.left + labelInsets.right : myPrefWidth; return new Dimension(width, fm.getHeight() + labelInsets.top + labelInsets.bottom); }