Dimension (JComponent c) { boolean canBeTrimmed = c.getClientProperty(BasicHTML.propertyKey) == null && ClientProperty.get(c, JLabelUtil.TRIM_OVERFLOW_KEY) != null; if (!canBeTrimmed) { return super.getMinimumSize(c); } JLabel label = (JLabel)c; String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); Insets insets = label.getInsets(null); Font font = label.getFont(); int xInsets = insets.left + insets.right; int yInsets = insets.top + insets.bottom; if (icon == null && (text == null || font == null)) { return new Dimension(xInsets, yInsets); } if (icon != null && (text == null || font == null)) { return new Dimension(icon.getIconWidth() + xInsets, icon.getIconHeight() + yInsets); } else { Rectangle allocation = new Rectangle(); FontMetrics fm = label.getFontMetrics(font); Rectangle iconR = new Rectangle(); Rectangle textR = new Rectangle(); allocation.x = insets.left; allocation.y = insets.top; allocation.width = insets.right; allocation.height = insets.bottom; layoutCL(label, fm, text, icon, allocation, iconR, textR); 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, y2 - y1); rv.width += xInsets; rv.height += yInsets; return rv; } }