e655. drawing text with mixed styles.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 11 行
TXT
11 行
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);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?