// Apply styles to text
AttributedString astr = new AttributedString("aString");
astr.addAttribute(TextAttribute.FONT, font, start, end);
astr.addAttribute(TextAttribute.BACKGROUND, color, start, end);

// Draw mixed-style text
TextLayout tl = new TextLayout(astr.getIterator(), g2d.getFontRenderContext());
tl.draw(g2d, x, y);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.