This example applies a new font and background color to a part of the text. You can apply styles to as many parts of the text as you need. See TextAttributes for available styles.

    // 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);

 

Related Examples

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2021-10-05
  • 2021-08-09
  • 2022-12-23
  • 2021-10-14
  • 2021-09-10
  • 2021-09-27
猜你喜欢
  • 2021-08-06
  • 2021-09-01
  • 2022-12-23
  • 2019-03-18
  • 2022-12-23
  • 2021-12-15
  • 2021-05-24
相关资源
相似解决方案