This Java tips demonstrates a method of drawing a text with mixed style on a Java component. The text can be drawn by overwriting the paint() function of the component. Here a developer may add a new font and background color to a part of the text. Different styles may be applied on different parts of text according to the need of the developer. This involves setting the attributes of the different text parts.

 // Apply styles to text from start to end which 
    // may be defined by the developer
    AttributedString textstr = new AttributedString("text");
    textstr.addAttribute(TextAttribute.FONT, font, start, end);
    textstr.addAttribute(TextAttribute.BACKGROUND, color, start, end);
    // Draw mixed-style text
    TextLayout layout = new TextLayout(textstr.getIterator(), 
    layout.draw(g2d, x, y);