java.awt.font
Class TextLayout

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.font.TextLayout
All Implemented Interfaces:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

public final class TextLayout
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable

TextLayout is an immutable graphical representation of styled character data.

It provides the following capabilities:

A TextLayout object can be rendered using its draw method.

TextLayout can be constructed either directly or through the use of a LineBreakMeasurer sample code for java.awt.font.LineBreakMeasurer definition code for java.awt.font.LineBreakMeasurer . When constructed directly, the source text represents a single paragraph. LineBreakMeasurer allows styled text to be broken into lines that fit within a particular width. See the LineBreakMeasurer documentation for more information.

TextLayout construction logically proceeds as follows:

All graphical information returned from a TextLayout object's methods is relative to the origin of the TextLayout, which is the intersection of the TextLayout object's baseline with its left edge. Also, coordinates passed into a TextLayout object's methods are assumed to be relative to the TextLayout object's origin. Clients usually need to translate between a TextLayout object's coordinate system and the coordinate system in another object (such as a Graphics sample code for java.awt.Graphics definition code for java.awt.Graphics object).

TextLayout objects are constructed from styled text, but they do not retain a reference to their source text. Thus, changes in the text previously used to generate a TextLayout do not affect the TextLayout.

Three methods on a TextLayout object (getNextRightHit, getNextLeftHit, and hitTestChar) return instances of TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo . The offsets contained in these TextHitInfo objects are relative to the start of the TextLayout, not to the text used to create the TextLayout. Similarly, TextLayout methods that accept TextHitInfo instances as parameters expect the TextHitInfo object's offsets to be relative to the TextLayout, not to any underlying text storage model.

Examples:

Constructing and drawing a TextLayout and its bounding rectangle:

   Graphics2D g = ...;
   Point2D loc = ...;
   Font font = Font.getFont("Helvetica-bold-italic");
   FontRenderContext frc = g.getFontRenderContext();
   TextLayout layout = new TextLayout("This is a string", font, frc);
   layout.draw(g, (float)loc.getX(), (float)loc.getY());

   Rectangle2D bounds = layout.getBounds();
   bounds.setRect(bounds.getX()+loc.getX(),
                  bounds.getY()+loc.getY(),
                  bounds.getWidth(),
                  bounds.getHeight());
   g.draw(bounds);
 

Hit-testing a TextLayout (determining which character is at a particular graphical location):

   Point2D click = ...;
   TextHitInfo hit = layout.hitTestChar(
                         (float) (click.getX() - loc.getX()),
                         (float) (click.getY() - loc.getY()));
 

Responding to a right-arrow key press:

   int insertionIndex = ...;
   TextHitInfo next = layout.getNextRightHit(insertionIndex);
   if (next != null) {
       // translate graphics to origin of layout on screen
       g.translate(loc.getX(), loc.getY());
       Shape[] carets = layout.getCaretShapes(next.getInsertionIndex());
       g.draw(carets[0]);
       if (carets[1] != null) {
           g.draw(carets[1]);
       }
   }
 

Drawing a selection range corresponding to a substring in the source text. The selected area may not be visually contiguous:

   // selStart, selLimit should be relative to the layout,
   // not to the source text

   int selStart = ..., selLimit = ...;
   Color selectionColor = ...;
   Shape selection = layout.getLogicalHighlightShape(selStart, selLimit);
   // selection may consist of disjoint areas
   // graphics is assumed to be tranlated to origin of layout
   g.setColor(selectionColor);
   g.fill(selection);
 

Drawing a visually contiguous selection range. The selection range may correspond to more than one substring in the source text. The ranges of the corresponding source text substrings can be obtained with getLogicalRangesForVisualSelection():

   TextHitInfo selStart = ..., selLimit = ...;
   Shape selection = layout.getVisualHighlightShape(selStart, selLimit);
   g.setColor(selectionColor);
   g.fill(selection);
   int[] ranges = getLogicalRangesForVisualSelection(selStart, selLimit);
   // ranges[0], ranges[1] is the first selection range,
   // ranges[2], ranges[3] is the second selection range, etc.
 

See Also:
LineBreakMeasurer sample code for java.awt.font.LineBreakMeasurer definition code for java.awt.font.LineBreakMeasurer , TextAttribute sample code for java.awt.font.TextAttribute definition code for java.awt.font.TextAttribute , TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo

Nested Class Summary
static class TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy
          Defines a policy for determining the strong caret location.
 
Field Summary
static TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy DEFAULT_CARET_POLICY sample code for java.awt.font.TextLayout.DEFAULT_CARET_POLICY definition code for java.awt.font.TextLayout.DEFAULT_CARET_POLICY
          This CaretPolicy is used when a policy is not specified by the client.
 
Constructor Summary
TextLayout sample code for java.awt.font.TextLayout.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext) (AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator  text, FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
          Constructs a TextLayout from an iterator over styled text.
TextLayout sample code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext) (String sample code for java.lang.String definition code for java.lang.String  string, Font sample code for java.awt.Font definition code for java.awt.Font  font, FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
          Constructs a TextLayout from a String and a Font sample code for java.awt.Font definition code for java.awt.Font .
TextLayout sample code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.util.Map, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout.TextLayout(java.lang.String, java.util.Map, java.awt.font.FontRenderContext) (String sample code for java.lang.String definition code for java.lang.String  string, Map sample code for java.util.Map definition code for java.util.Map <? extends AttributedCharacterIterator.Attribute sample code for java.text.AttributedCharacterIterator.Attribute definition code for java.text.AttributedCharacterIterator.Attribute ,?> attributes, FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
          Constructs a TextLayout from a String and an attribute set.
 
Method Summary
protected  Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for java.awt.font.TextLayout.clone() definition code for java.awt.font.TextLayout.clone() ()
          Creates a copy of this TextLayout.
 void draw sample code for java.awt.font.TextLayout.draw(java.awt.Graphics2D, float, float) definition code for java.awt.font.TextLayout.draw(java.awt.Graphics2D, float, float) (Graphics2D sample code for java.awt.Graphics2D definition code for java.awt.Graphics2D  g2, float x, float y)
          Renders this TextLayout at the specified location in the specified Graphics2D sample code for java.awt.Graphics2D definition code for java.awt.Graphics2D context.
 boolean equals sample code for java.awt.font.TextLayout.equals(java.lang.Object) definition code for java.awt.font.TextLayout.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Returns true if the specified Object is a TextLayout object and if the specified Object equals this TextLayout.
 boolean equals sample code for java.awt.font.TextLayout.equals(java.awt.font.TextLayout) definition code for java.awt.font.TextLayout.equals(java.awt.font.TextLayout) (TextLayout sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout  rhs)
          Returns true if the two layouts are equal.
 float getAdvance sample code for java.awt.font.TextLayout.getAdvance() definition code for java.awt.font.TextLayout.getAdvance() ()
          Returns the advance of this TextLayout.
 float getAscent sample code for java.awt.font.TextLayout.getAscent() definition code for java.awt.font.TextLayout.getAscent() ()
          Returns the ascent of this TextLayout.
 byte getBaseline sample code for java.awt.font.TextLayout.getBaseline() definition code for java.awt.font.TextLayout.getBaseline() ()
          Returns the baseline for this TextLayout.
 float[] getBaselineOffsets sample code for java.awt.font.TextLayout.getBaselineOffsets() definition code for java.awt.font.TextLayout.getBaselineOffsets() ()
          Returns the offsets array for the baselines used for this TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getBlackBoxBounds sample code for java.awt.font.TextLayout.getBlackBoxBounds(int, int) definition code for java.awt.font.TextLayout.getBlackBoxBounds(int, int) (int firstEndpoint, int secondEndpoint)
          Returns the black box bounds of the characters in the specified range.
 Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D getBounds sample code for java.awt.font.TextLayout.getBounds() definition code for java.awt.font.TextLayout.getBounds() ()
          Returns the bounds of this TextLayout.
 float[] getCaretInfo sample code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns information about the caret corresponding to hit.
 float[] getCaretInfo sample code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretInfo(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns information about the caret corresponding to hit.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getCaretShape sample code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns a Shape representing the caret at the specified hit inside the natural bounds of this TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getCaretShape sample code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretShape(java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a Shape sample code for java.awt.Shape definition code for java.awt.Shape representing the caret at the specified hit inside the specified bounds.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int) definition code for java.awt.font.TextLayout.getCaretShapes(int) (int offset)
          Returns two paths corresponding to the strong and weak caret.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D) (int offset, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns two paths corresponding to the strong and weak caret.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape [] getCaretShapes sample code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getCaretShapes(int, java.awt.geom.Rectangle2D, java.awt.font.TextLayout.CaretPolicy) (int offset, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds, TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
          Returns two paths corresponding to the strong and weak caret.
 int getCharacterCount sample code for java.awt.font.TextLayout.getCharacterCount() definition code for java.awt.font.TextLayout.getCharacterCount() ()
          Returns the number of characters represented by this TextLayout.
 byte getCharacterLevel sample code for java.awt.font.TextLayout.getCharacterLevel(int) definition code for java.awt.font.TextLayout.getCharacterLevel(int) (int index)
          Returns the level of the character at index.
 float getDescent sample code for java.awt.font.TextLayout.getDescent() definition code for java.awt.font.TextLayout.getDescent() ()
          Returns the descent of this TextLayout.
 TextLayout sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout getJustifiedLayout sample code for java.awt.font.TextLayout.getJustifiedLayout(float) definition code for java.awt.font.TextLayout.getJustifiedLayout(float) (float justificationWidth)
          Creates a copy of this TextLayout justified to the specified width.
 float getLeading sample code for java.awt.font.TextLayout.getLeading() definition code for java.awt.font.TextLayout.getLeading() ()
          Returns the leading of the TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getLogicalHighlightShape sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int) (int firstEndpoint, int secondEndpoint)
          Returns a Shape enclosing the logical selection in the specified range, extended to the natural bounds of this TextLayout.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getLogicalHighlightShape sample code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getLogicalHighlightShape(int, int, java.awt.geom.Rectangle2D) (int firstEndpoint, int secondEndpoint, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a Shape enclosing the logical selection in the specified range, extended to the specified bounds.
 int[] getLogicalRangesForVisualSelection sample code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getLogicalRangesForVisualSelection(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint, TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint)
          Returns the logical ranges of text corresponding to a visual selection.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(int) definition code for java.awt.font.TextLayout.getNextLeftHit(int) (int offset)
          Returns the hit for the next caret to the left (top); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(int, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getNextLeftHit(int, java.awt.font.TextLayout.CaretPolicy) (int offset, TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
          Returns the hit for the next caret to the left (top); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextLeftHit sample code for java.awt.font.TextLayout.getNextLeftHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getNextLeftHit(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns the hit for the next caret to the left (top); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(int) definition code for java.awt.font.TextLayout.getNextRightHit(int) (int offset)
          Returns the hit for the next caret to the right (bottom); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(int, java.awt.font.TextLayout.CaretPolicy) definition code for java.awt.font.TextLayout.getNextRightHit(int, java.awt.font.TextLayout.CaretPolicy) (int offset, TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  policy)
          Returns the hit for the next caret to the right (bottom); if no such hit, returns null.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getNextRightHit sample code for java.awt.font.TextLayout.getNextRightHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getNextRightHit(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns the hit for the next caret to the right (bottom); if there is no such hit, returns null.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getOutline sample code for java.awt.font.TextLayout.getOutline(java.awt.geom.AffineTransform) definition code for java.awt.font.TextLayout.getOutline(java.awt.geom.AffineTransform) (AffineTransform sample code for java.awt.geom.AffineTransform definition code for java.awt.geom.AffineTransform  tx)
          Returns a Shape representing the outline of this TextLayout.
 float getVisibleAdvance sample code for java.awt.font.TextLayout.getVisibleAdvance() definition code for java.awt.font.TextLayout.getVisibleAdvance() ()
          Returns the advance of this TextLayout, minus trailing whitespace.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getVisualHighlightShape sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint, TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint)
          Returns a Shape enclosing the visual selection in the specified range, extended to the bounds.
 Shape sample code for java.awt.Shape definition code for java.awt.Shape getVisualHighlightShape sample code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.getVisualHighlightShape(java.awt.font.TextHitInfo, java.awt.font.TextHitInfo, java.awt.geom.Rectangle2D) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  firstEndpoint, TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  secondEndpoint, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a path enclosing the visual selection in the specified range, extended to bounds.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getVisualOtherHit sample code for java.awt.font.TextLayout.getVisualOtherHit(java.awt.font.TextHitInfo) definition code for java.awt.font.TextLayout.getVisualOtherHit(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hit)
          Returns the hit on the opposite side of the specified hit's caret.
protected  void handleJustify sample code for java.awt.font.TextLayout.handleJustify(float) definition code for java.awt.font.TextLayout.handleJustify(float) (float justificationWidth)
          Justify this layout.
 int hashCode sample code for java.awt.font.TextLayout.hashCode() definition code for java.awt.font.TextLayout.hashCode() ()
          Returns the hash code of this TextLayout.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo hitTestChar sample code for java.awt.font.TextLayout.hitTestChar(float, float) definition code for java.awt.font.TextLayout.hitTestChar(float, float) (float x, float y)
          Returns a TextHitInfo corresponding to the specified point.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo hitTestChar sample code for java.awt.font.TextLayout.hitTestChar(float, float, java.awt.geom.Rectangle2D) definition code for java.awt.font.TextLayout.hitTestChar(float, float, java.awt.geom.Rectangle2D) (float x, float y, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds)
          Returns a TextHitInfo corresponding to the specified point.
 boolean isLeftToRight sample code for java.awt.font.TextLayout.isLeftToRight() definition code for java.awt.font.TextLayout.isLeftToRight() ()
          Returns true if this TextLayout has a left-to-right base direction or false if it has a right-to-left base direction.
 boolean isVertical sample code for java.awt.font.TextLayout.isVertical() definition code for java.awt.font.TextLayout.isVertical() ()
          Returns true if this TextLayout is vertical.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.font.TextLayout.toString() definition code for java.awt.font.TextLayout.toString() ()
          Returns debugging information for this TextLayout.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

DEFAULT_CARET_POLICY sample code for java.awt.font.TextLayout.DEFAULT_CARET_POLICY

public static final TextLayout.CaretPolicy sample code for java.awt.font.TextLayout.CaretPolicy definition code for java.awt.font.TextLayout.CaretPolicy  DEFAULT_CARET_POLICY
This CaretPolicy is used when a policy is not specified by the client. With this policy, a hit on a character whose direction is the same as the line direction is stronger than a hit on a counterdirectional character. If the characters' directions are the same, a hit on the leading edge of a character is stronger than a hit on the trailing edge of a character.

Constructor Detail

TextLayout sample code for java.awt.font.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext)

public TextLayout(String sample code for java.lang.String definition code for java.lang.String  string,
                  Font sample code for java.awt.Font definition code for java.awt.Font  font,
                  FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
Constructs a TextLayout from a String and a Font sample code for java.awt.Font definition code for java.awt.Font . All the text is styled using the specified Font.

The String must specify a single paragraph of text, because an entire paragraph is required for the bidirectional algorithm.

Parameters:
string - the text to display
font - a Font used to style the text
frc - contains information about a graphics device which is needed to measure the text correctly. Text measurements can vary slightly depending on the device resolution, and attributes such as antialiasing. This parameter does not specify a translation between the TextLayout and user space.

TextLayout sample code for java.awt.font.TextLayout(java.lang.String, java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute, ?>, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout(java.lang.String, java.util.Map<? extends java.text.AttributedCharacterIterator.Attribute, ?>, java.awt.font.FontRenderContext)

public TextLayout(String sample code for java.lang.String definition code for java.lang.String  string,
                  Map sample code for java.util.Map definition code for java.util.Map <? extends AttributedCharacterIterator.Attribute sample code for java.text.AttributedCharacterIterator.Attribute definition code for java.text.AttributedCharacterIterator.Attribute ,?> attributes,
                  FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext  frc)
Constructs a TextLayout from a String and an attribute set.

All the text is styled using the provided attributes.

string must specify a single paragraph of text because an entire paragraph is required for the bidirectional algorithm.

Parameters:
string - the text to display
attributes - the attributes used to style the text
frc - contains information about a graphics device which is needed to measure the text correctly. Text measurements can vary slightly depending on the device resolution, and attributes such as antialiasing. This parameter does not specify a translation between the TextLayout and user space.

TextLayout sample code for java.awt.font.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext) definition code for java.awt.font.TextLayout(java.text.AttributedCharacterIterator, java.awt.font.FontRenderContext)

public TextLayout(AttributedCharacterIterator sample code for java.text.AttributedCharacterIterator definition code for java.text.AttributedCharacterIterator  text,
                  FontRenderContext sample code for java.awt.font.FontRenderContext definition code for java.awt.font.FontRenderContext