Dimension () { FontMetrics defFontMetrics = getFontMetrics(getFont()); int width = getTextOffset(); if (!myText.isEmpty()){ if (myHighlightedRegions.isEmpty()){ width += getStringWidth(myText, defFontMetrics); } else{ int endIndex = 0; for (HighlightedRegion hRegion : myHighlightedRegions) { width += getStringWidth(myText.substring(endIndex, hRegion.startOffset), defFontMetrics); endIndex = hRegion.endOffset; String text = getRegionText(hRegion); Font regFont = getFont().deriveFont(hRegion.textAttributes.getFontType()); FontMetrics fontMetrics = getFontMetrics(regFont); width += getStringWidth(text, fontMetrics); } width += getStringWidth(myText.substring(endIndex), defFontMetrics); } } int height = defFontMetrics.getHeight() + defFontMetrics.getLeading(); if (myIcon != null){ height = Math.max(myIcon.getIconHeight() + defFontMetrics.getLeading(), height); width += myIcon.getIconWidth(); } return new Dimension(width + 2, height); }