![]() |
The Java Developers Almanac 1.4 |
|
e655. Drawing Text with Mixed StylesThis 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. SeeTextAttributes 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);
e652. Getting the Font Faces for a Font Family e653. Drawing a Paragraph of Text e654. Getting the Shape from the Outline of Text © 2002 Addison-Wesley. |