Module java.desktop
Package java.awt.font

Class TextAttribute

java.lang.Object
All Implemented Interfaces:
Serializable

public final class TextAttribute extends AttributedCharacterIterator.Attribute
The TextAttribute class defines attribute keys and attribute values used for text rendering.

TextAttribute instances are used as attribute keys to identify attributes in Font, TextLayout, AttributedCharacterIterator, and other classes handling text attributes. Other constants defined in this class can be used as attribute values.

For each text attribute, the documentation provides:

  • the type of its value,
  • the relevant predefined constants, if any
  • the default effect if the attribute is absent
  • the valid values if there are limitations
  • a description of the effect.

Values

  • The values of attributes must always be immutable.
  • Where value limitations are given, any value outside of that set is reserved for future use; the value will be treated as the default.
  • The value null is treated the same as the default value and results in the default behavior.
  • If the value is not of the proper type, the attribute will be ignored.
  • The identity of the value does not matter, only the actual value. For example, TextAttribute.WEIGHT_BOLD and Float.valueOf(2.0f) indicate the same WEIGHT.
  • Attribute values of type Number (used for WEIGHT, WIDTH, POSTURE, SIZE, JUSTIFICATION, and TRACKING) can vary along their natural range and are not restricted to the predefined constants. Number.floatValue() is used to get the actual value from the Number.
  • The values for WEIGHT, WIDTH, and POSTURE are interpolated by the system, which can select the 'nearest available' font or use other techniques to approximate the user's request.

Summary of attributes

Key, value type, principal constants, and default value behavior of all TextAttributes
Key Value Type Principal Constants Default Value
FAMILY String See Font DIALOG, DIALOG_INPUT,
SERIF, SANS_SERIF, and MONOSPACED.
"Default" (use platform default)
WEIGHT Number WEIGHT_REGULAR, WEIGHT_BOLD WEIGHT_REGULAR
WIDTH Number WIDTH_CONDENSED, WIDTH_REGULAR,
WIDTH_EXTENDED
WIDTH_REGULAR
POSTURE Number POSTURE_REGULAR, POSTURE_OBLIQUE POSTURE_REGULAR
SIZE Number none 12.0
TRANSFORM TransformAttribute See TransformAttribute IDENTITY TransformAttribute.IDENTITY
SUPERSCRIPT Integer SUPERSCRIPT_SUPER, SUPERSCRIPT_SUB 0 (use the standard glyphs and metrics)
FONT Font none null (do not override font resolution)
CHAR_REPLACEMENT GraphicAttribute none null (draw text using font glyphs)
FOREGROUND Paint none null (use current graphics paint)
BACKGROUND Paint none null (do not render background)
UNDERLINE Integer UNDERLINE_ON -1 (do not render underline)
STRIKETHROUGH Boolean STRIKETHROUGH_ON false (do not render strikethrough)
RUN_DIRECTION Boolean RUN_DIRECTION_LTR
RUN_DIRECTION_RTL
null (use Bidi standard default)
BIDI_EMBEDDING Integer none 0 (use base line direction)
JUSTIFICATION Number JUSTIFICATION_FULL JUSTIFICATION_FULL
INPUT_METHOD_HIGHLIGHT InputMethodHighlight,
Annotation
(see class) null (do not apply input highlighting)
INPUT_METHOD_UNDERLINE Integer UNDERLINE_LOW_ONE_PIXEL,
UNDERLINE_LOW_TWO_PIXEL
-1 (do not render underline)
SWAP_COLORS Boolean SWAP_COLORS_ON false (do not swap colors)
NUMERIC_SHAPING NumericShaper none null (do not shape digits)
KERNING Integer KERNING_ON 0 (do not request kerning)
LIGATURES Integer LIGATURES_ON 0 (do not form optional ligatures)
TRACKING Number TRACKING_LOOSE, TRACKING_TIGHT 0 (do not add tracking)
See Also: