void (Graphics g) { // determine color of background Color bgColor; Color fgColor; boolean paintHighlightsBackground; boolean paintHighlightsForeground; if (myIsSelected && (myHasFocus || myPaintUnfocusedSelection)) { bgColor = UIUtil.getTreeSelectionBackground(); fgColor = UIUtil.getTreeSelectionForeground(); paintHighlightsBackground = false; paintHighlightsForeground = false; } else { bgColor = myEnforcedBackground == null ? UIUtil.getTreeBackground() : myEnforcedBackground; fgColor = getForeground(); paintHighlightsBackground = isOpaque(); paintHighlightsForeground = true; } if (myDoNotHighlight) { paintHighlightsForeground = false; } // paint background int textOffset = getTextOffset(); int offset = textOffset; if (isOpaque()) { g.setColor(getBackground()); g.fillRect(0, 0, Math.max(0, textOffset - 2), getHeight()); g.setColor(bgColor); g.fillRect(Math.max(0, textOffset - 2), 0, getWidth(), getHeight()); } // paint icon if (myIcon != null) { int x = getIconOffset(); myIcon.paintIcon(this, g, x, (getHeight() - myIcon.getIconHeight()) / 2); } // paint text applyRenderingHints(g); FontMetrics defFontMetrics = getFontMetrics(getFont()); if (myText == null) { myText = ""; } // center text inside the component: final int yOffset = (getHeight() - defFontMetrics.getMaxAscent() - defFontMetrics.getMaxDescent()) / 2 + defFontMetrics.getMaxAscent(); if (myHighlightedRegions.isEmpty()){ g.setColor(fgColor); g.drawString(myText, textOffset, yOffset/*defFontMetrics.getMaxAscent()*/); } else{ int endIndex = 0; for (HighlightedRegion hRegion : myHighlightedRegions) { String text = myText.substring(endIndex, hRegion.startOffset); endIndex = hRegion.endOffset; // draw plain text if (!text.isEmpty()) { g.setColor(fgColor); g.setFont(defFontMetrics.getFont()); g.drawString(text, offset, yOffset/*defFontMetrics.getMaxAscent()*/); offset += getStringWidth(text, defFontMetrics); } Font regFont = getFont().deriveFont(hRegion.textAttributes.getFontType()); FontMetrics fontMetrics = getFontMetrics(regFont); text = myText.substring(hRegion.startOffset, hRegion.endOffset); // paint highlight background if (hRegion.textAttributes.getBackgroundColor() != null && paintHighlightsBackground) { g.setColor(hRegion.textAttributes.getBackgroundColor()); g.fillRect(offset, 0, getStringWidth(text, fontMetrics), fontMetrics.getHeight() + fontMetrics.getLeading()); } // draw highlight text if (hRegion.textAttributes.getForegroundColor() != null && paintHighlightsForeground) { g.setColor(hRegion.textAttributes.getForegroundColor()); } else { g.setColor(fgColor); } g.setFont(fontMetrics.getFont()); g.drawString(text, offset, yOffset/*fontMetrics.getMaxAscent()*/); // draw highlight underscored line if (hRegion.textAttributes.getEffectType() != null && hRegion.textAttributes.getEffectColor() != null) { g.setColor(hRegion.textAttributes.getEffectColor()); int y = yOffset/*fontMetrics.getMaxAscent()*/ + 2; LinePainter2D.paint((Graphics2D)g, offset, y, offset + getStringWidth(text, fontMetrics) - 1, y); } // draw highlight border if (hRegion.textAttributes.getEffectColor() != null && hRegion.textAttributes.getEffectType() == EffectType.BOXED) { g.setColor(hRegion.textAttributes.getEffectColor()); g.drawRect(offset, 0, getStringWidth(text, fontMetrics) - 1, fontMetrics.getHeight() + fontMetrics.getLeading() - 1); } offset += getStringWidth(text, fontMetrics); } String text = myText.substring(endIndex); if (!text.isEmpty()){ g.setColor(fgColor); g.setFont(defFontMetrics.getFont()); g.drawString(text, offset, yOffset/*defFontMetrics.getMaxAscent()*/); } } // paint border if (myIsSelected){ g.setColor(UIUtil.getTreeSelectionBorderColor()); UIUtil.drawDottedRectangle(g, textOffset - 2, 0, getWidth() - 1, getHeight() - 1); } super.paintComponent(g); }