View RSS Feed

Java AWT

Using Text Attributes to Style Text

Rate this Entry
by , 03-07-2012 at 04:54 PM (1174 Views)
Following text attributes needs to be applied by an application:
  • Underline –Underneath text, a line is drawn.
  • Strikethrough –Through the text, a horizontal line gets drawn.
  • Superscript or Subscript –A Letter of a text which slightly appears below or above a line.
  • Kerning – The space adjustments between characters


Such text attributes might get applied, by using the Java 2D™ TextAttribute class.

Text attributes are applied by adding them to a Font object. E.g:
Java Code:
Map<TextAttribute, Object> map =
    new Hashtable<TextAttribute, Object>();
map.put(TextAttribute.KERNING,
    TextAttribute.KERNING_ON);
font = font.deriveFont(map);
graphics.setFont(font);
The code example given below specifies the application of text attributes, in the following order:
Sample string (no text attributes applied)
  1. Kerning
  2. Kerning and Underlining
  3. Kerning,Underlining and Strikethrough
  4. Kerning,Underlining, Strikethrough and Color

Submit "Using Text Attributes to Style Text" to Facebook Submit "Using Text Attributes to Style Text" to Digg Submit "Using Text Attributes to Style Text" to del.icio.us Submit "Using Text Attributes to Style Text" to StumbleUpon Submit "Using Text Attributes to Style Text" to Google

Categories
Graphics

Comments