Class TextLayout

java.lang.Object
org.eclipse.swt.graphics.Resource
org.eclipse.swt.graphics.TextLayout

public final class TextLayout extends Resource
TextLayout is a graphic object that represents styled text.

Instances of this class provide support for drawing, cursor navigation, hit testing, text wrapping, alignment, tab expansion line breaking, etc. These are aspects required for rendering internationalized text.

Application code must explicitly invoke the TextLayout#dispose() method to release the operating system resources managed by each instance when those instances are no longer required.

Since:
3.0
See Also:
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Constructs a new instance of this class on the given device.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    draw(GC gc, int x, int y)
    Draws the receiver's text using the specified GC at the specified point.
    void
    draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)
    Draws the receiver's text using the specified GC at the specified point.
    void
    draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags)
    Draws the receiver's text using the specified GC at the specified point.
    int
    Returns the receiver's horizontal text alignment, which will be one of SWT.LEFT, SWT.CENTER or SWT.RIGHT.
    int
    Returns the ascent of the receiver.
    Returns the bounds of the receiver.
    getBounds(int start, int end)
    Returns the bounds for the specified range of characters.
    int
    Returns the descent of the receiver.
    Returns the default font currently being used by the receiver to draw and measure text.
    int
    Returns the receiver's indent.
    boolean
    Returns the receiver's justification.
    int
    getLevel(int offset)
    Returns the embedding level for the specified character offset.
    getLineBounds(int lineIndex)
    Returns the bounds of the line for the specified line index.
    int
    Returns the receiver's line count.
    int
    getLineIndex(int offset)
    Returns the index of the line that contains the specified character offset.
    getLineMetrics(int lineIndex)
    Returns the font metrics for the specified line index.
    int[]
    Returns the line offsets.
    getLocation(int offset, boolean trailing)
    Returns the location for the specified character offset.
    int
    getNextOffset(int offset, int movement)
    Returns the next offset for the specified offset and movement type.
    int
    getOffset(int x, int y, int[] trailing)
    Returns the character offset for the specified point.
    int
    getOffset(Point point, int[] trailing)
    Returns the character offset for the specified point.
    int
    Returns the orientation of the receiver.
    int
    getPreviousOffset(int offset, int movement)
    Returns the previous offset for the specified offset and movement type.
    int[]
    Gets the ranges of text that are associated with a TextStyle.
    int[]
    Returns the text segments offsets of the receiver.
    char[]
    Returns the segments characters of the receiver.
    int
    Returns the line spacing of the receiver.
    getStyle(int offset)
    Gets the style of the receiver at the specified character offset.
    Gets all styles of the receiver.
    int[]
    Returns the tab list of the receiver.
    Gets the receiver's text, which will be an empty string if it has never been set.
    int
    Returns the text direction of the receiver.
    int
    Returns the vertical indent of the receiver.
    int
    Returns the width of the receiver.
    int
    Returns the receiver's wrap indent.
    boolean
    Returns true if the text layout has been disposed, and false otherwise.
    void
    setAlignment(int alignment)
    Sets the text alignment for the receiver.
    void
    setAscent(int ascent)
    Sets the ascent of the receiver.
    void
    setDefaultTabWidth(int tabLength)
    Sets Default Tab Width in terms if number of space characters.
    void
    setDescent(int descent)
    Sets the descent of the receiver.
    void
    Forces line heights in receiver to obey provided value.
    void
    setFont(Font font)
    Sets the default font which will be used by the receiver to draw and measure text.
    void
    setIndent(int indent)
    Sets the indent of the receiver.
    void
    setJustify(boolean justify)
    Sets the justification of the receiver.
    void
    setOrientation(int orientation)
    Sets the orientation of the receiver, which must be one of SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
    void
    setSegments(int[] segments)
    Sets the offsets of the receiver's text segments.
    void
    setSegmentsChars(char[] segmentsChars)
    Sets the characters to be used in the segments boundaries.
    void
    setSpacing(int spacing)
    Sets the line spacing of the receiver.
    void
    setStyle(TextStyle style, int start, int end)
    Sets the style of the receiver for the specified range.
    void
    setTabs(int[] tabs)
    Sets the receiver's tab list.
    void
    Sets the receiver's text.
    void
    setTextDirection(int textDirection)
    Sets the text direction of the receiver, which must be one of SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT or SWT.AUTO_TEXT_DIRECTION.
    void
    setVerticalIndent(int verticalIndent)
    Sets the vertical indent of the receiver.
    void
    setWidth(int width)
    Sets the line width of the receiver, which determines how text should be wrapped and aligned.
    void
    setWrapIndent(int wrapIndent)
    Sets the wrap indent of the receiver.
    Returns a string containing a concise, human-readable description of the receiver.

    Methods inherited from class org.eclipse.swt.graphics.Resource Link icon

    dispose, getDevice, setNonDisposeHandler

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • TextLayout Link icon

      public TextLayout(Device device)
      Constructs a new instance of this class on the given device.

      You must dispose the text layout when it is no longer required.

      Parameters:
      device - the device on which to allocate the text layout
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if device is null and there is no current device
      See Also:
  • Method Details Link icon

    • draw Link icon

      public void draw(GC gc, int x, int y)
      Draws the receiver's text using the specified GC at the specified point.
      Parameters:
      gc - the GC to draw
      x - the x coordinate of the top left corner of the rectangular area where the text is to be drawn
      y - the y coordinate of the top left corner of the rectangular area where the text is to be drawn
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the gc is null
    • draw Link icon

      public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)
      Draws the receiver's text using the specified GC at the specified point.
      Parameters:
      gc - the GC to draw
      x - the x coordinate of the top left corner of the rectangular area where the text is to be drawn
      y - the y coordinate of the top left corner of the rectangular area where the text is to be drawn
      selectionStart - the offset where the selections starts, or -1 indicating no selection
      selectionEnd - the offset where the selections ends, or -1 indicating no selection
      selectionForeground - selection foreground, or NULL to use the system default color
      selectionBackground - selection background, or NULL to use the system default color
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the gc is null
    • draw Link icon

      public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags)
      Draws the receiver's text using the specified GC at the specified point.

      The parameter flags can include one of SWT.DELIMITER_SELECTION or SWT.FULL_SELECTION to specify the selection behavior on all lines except for the last line, and can also include SWT.LAST_LINE_SELECTION to extend the specified selection behavior to the last line.

      Parameters:
      gc - the GC to draw
      x - the x coordinate of the top left corner of the rectangular area where the text is to be drawn
      y - the y coordinate of the top left corner of the rectangular area where the text is to be drawn
      selectionStart - the offset where the selections starts, or -1 indicating no selection
      selectionEnd - the offset where the selections ends, or -1 indicating no selection
      selectionForeground - selection foreground, or NULL to use the system default color
      selectionBackground - selection background, or NULL to use the system default color
      flags - drawing options
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the gc is null
      Since:
      3.3
    • getAlignment Link icon

      public int getAlignment()
      Returns the receiver's horizontal text alignment, which will be one of SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      Returns:
      the alignment used to positioned text horizontally
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getAscent Link icon

      public int getAscent()
      Returns the ascent of the receiver.
      Returns:
      the ascent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getBounds Link icon

      public Rectangle getBounds()
      Returns the bounds of the receiver. The width returned is either the width of the longest line or the width set using setWidth(int). To obtain the text bounds of a line use getLineBounds(int).
      Returns:
      the bounds of the receiver
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getBounds Link icon

      public Rectangle getBounds(int start, int end)
      Returns the bounds for the specified range of characters. The bounds is the smallest rectangle that encompasses all characters in the range. The start and end offsets are inclusive and will be clamped if out of range.
      Parameters:
      start - the start offset
      end - the end offset
      Returns:
      the bounds of the character range
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getDescent Link icon

      public int getDescent()
      Returns the descent of the receiver.
      Returns:
      the descent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getFont Link icon

      public Font getFont()
      Returns the default font currently being used by the receiver to draw and measure text.
      Returns:
      the receiver's font
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getIndent Link icon

      public int getIndent()
      Returns the receiver's indent.
      Returns:
      the receiver's indent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.2
    • getJustify Link icon

      public boolean getJustify()
      Returns the receiver's justification.
      Returns:
      the receiver's justification
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.2
    • getLevel Link icon

      public int getLevel(int offset)
      Returns the embedding level for the specified character offset. The embedding level is usually used to determine the directionality of a character in bidirectional text.
      Parameters:
      offset - the character offset
      Returns:
      the embedding level
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the character offset is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getLineBounds Link icon

      public Rectangle getLineBounds(int lineIndex)
      Returns the bounds of the line for the specified line index.
      Parameters:
      lineIndex - the line index
      Returns:
      the line bounds
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the line index is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getLineCount Link icon

      public int getLineCount()
      Returns the receiver's line count. This includes lines caused by wrapping.
      Returns:
      the line count
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getLineIndex Link icon

      public int getLineIndex(int offset)
      Returns the index of the line that contains the specified character offset.
      Parameters:
      offset - the character offset
      Returns:
      the line index
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the character offset is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getLineMetrics Link icon

      public FontMetrics getLineMetrics(int lineIndex)
      Returns the font metrics for the specified line index.
      Parameters:
      lineIndex - the line index
      Returns:
      the font metrics
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the line index is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getLineOffsets Link icon

      public int[] getLineOffsets()
      Returns the line offsets. Each value in the array is the offset for the first character in a line except for the last value, which contains the length of the text.
      Returns:
      the line offsets
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getLocation Link icon

      public Point getLocation(int offset, boolean trailing)
      Returns the location for the specified character offset. The trailing argument indicates whether the offset corresponds to the leading or trailing edge of the cluster.
      Parameters:
      offset - the character offset
      trailing - the trailing flag
      Returns:
      the location of the character offset
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getNextOffset Link icon

      public int getNextOffset(int offset, int movement)
      Returns the next offset for the specified offset and movement type. The movement is one of SWT.MOVEMENT_CHAR, SWT.MOVEMENT_CLUSTER, SWT.MOVEMENT_WORD, SWT.MOVEMENT_WORD_END or SWT.MOVEMENT_WORD_START.
      Parameters:
      offset - the start offset
      movement - the movement type
      Returns:
      the next offset
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the offset is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getOffset Link icon

      public int getOffset(Point point, int[] trailing)
      Returns the character offset for the specified point. For a typical character, the trailing argument will be filled in to indicate whether the point is closer to the leading edge (0) or the trailing edge (1). When the point is over a cluster composed of multiple characters, the trailing argument will be filled with the position of the character in the cluster that is closest to the point.
      Parameters:
      point - the point
      trailing - the trailing buffer
      Returns:
      the character offset
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the trailing length is less than 1
      • ERROR_NULL_ARGUMENT - if the point is null
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getOffset Link icon

      public int getOffset(int x, int y, int[] trailing)
      Returns the character offset for the specified point. For a typical character, the trailing argument will be filled in to indicate whether the point is closer to the leading edge (0) or the trailing edge (1). When the point is over a cluster composed of multiple characters, the trailing argument will be filled with the position of the character in the cluster that is closest to the point.
      Parameters:
      x - the x coordinate of the point
      y - the y coordinate of the point
      trailing - the trailing buffer
      Returns:
      the character offset
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the trailing length is less than 1
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getOrientation Link icon

      public int getOrientation()
      Returns the orientation of the receiver.
      Returns:
      the orientation style
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getPreviousOffset Link icon

      public int getPreviousOffset(int offset, int movement)
      Returns the previous offset for the specified offset and movement type. The movement is one of SWT.MOVEMENT_CHAR, SWT.MOVEMENT_CLUSTER or SWT.MOVEMENT_WORD, SWT.MOVEMENT_WORD_END or SWT.MOVEMENT_WORD_START.
      Parameters:
      offset - the start offset
      movement - the movement type
      Returns:
      the previous offset
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the offset is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • getRanges Link icon

      public int[] getRanges()
      Gets the ranges of text that are associated with a TextStyle.
      Returns:
      the ranges, an array of offsets representing the start and end of each text style.
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.2
      See Also:
    • getSegments Link icon

      public int[] getSegments()
      Returns the text segments offsets of the receiver.
      Returns:
      the text segments offsets
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getSegmentsChars Link icon

      public char[] getSegmentsChars()
      Returns the segments characters of the receiver.
      Returns:
      the segments characters
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.6
    • getSpacing Link icon

      public int getSpacing()
      Returns the line spacing of the receiver.
      Returns:
      the line spacing
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getVerticalIndent Link icon

      public int getVerticalIndent()
      Returns the vertical indent of the receiver.
      Returns:
      the vertical indent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.109
    • getStyle Link icon

      public TextStyle getStyle(int offset)
      Gets the style of the receiver at the specified character offset.
      Parameters:
      offset - the text offset
      Returns:
      the style or null if not set
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the character offset is out of range
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getStyles Link icon

      public TextStyle[] getStyles()
      Gets all styles of the receiver.
      Returns:
      the styles
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.2
      See Also:
    • getTabs Link icon

      public int[] getTabs()
      Returns the tab list of the receiver.
      Returns:
      the tab list
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getText Link icon

      public String getText()
      Gets the receiver's text, which will be an empty string if it has never been set.
      Returns:
      the receiver's text
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getTextDirection Link icon

      public int getTextDirection()
      Returns the text direction of the receiver.
      Returns:
      the text direction value
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.103
    • getWidth Link icon

      public int getWidth()
      Returns the width of the receiver.
      Returns:
      the width
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • getWrapIndent Link icon

      public int getWrapIndent()
      Returns the receiver's wrap indent.
      Returns:
      the receiver's wrap indent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.6
    • isDisposed Link icon

      public boolean isDisposed()
      Returns true if the text layout has been disposed, and false otherwise.

      This method gets the dispose state for the text layout. When a text layout has been disposed, it is an error to invoke any other method (except Resource.dispose()) using the text layout.

      Specified by:
      isDisposed in class Resource
      Returns:
      true when the text layout is disposed and false otherwise
    • setAlignment Link icon

      public void setAlignment(int alignment)
      Sets the text alignment for the receiver. The alignment controls how a line of text is positioned horizontally. The argument should be one of SWT.LEFT, SWT.RIGHT or SWT.CENTER.

      The default alignment is SWT.LEFT. Note that the receiver's width must be set in order to use SWT.RIGHT or SWT.CENTER alignment.

      Parameters:
      alignment - the new alignment
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • setAscent Link icon

      public void setAscent(int ascent)
      Sets the ascent of the receiver. The ascent is distance in points from the baseline to the top of the line and it is applied to all lines. The default value is -1 which means that the ascent is calculated from the line fonts.
      Parameters:
      ascent - the new ascent
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the ascent is less than -1
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • setDescent Link icon

      public void setDescent(int descent)
      Sets the descent of the receiver. The descent is distance in points from the baseline to the bottom of the line and it is applied to all lines. The default value is -1 which means that the descent is calculated from the line fonts.
      Parameters:
      descent - the new descent
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the descent is less than -1
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • setFixedLineMetrics Link icon

      public void setFixedLineMetrics(FontMetrics metrics)
      Forces line heights in receiver to obey provided value. This is useful with texts that contain glyphs from different scripts, such as mixing latin glyphs with hieroglyphs or emojis.

      Text lines with different metrics will be forced to fit. This means painting text in such a way that its baseline is where specified by given 'metrics'. This can sometimes introduce small visual artifacs, such as taller lines overpainting or being clipped by content above and below.

      The possible ways to set FontMetrics include:
      • Obtaining 'FontMetrics' via GC.getFontMetrics(). Note that this will only obtain metrics for currently selected font and will not account for font fallbacks (for example, with a latin font selected, painting hieroglyphs usually involves a fallback font).
      • Obtaining 'FontMetrics' via a temporary 'TextLayout'. This would involve setting a desired text sample to 'TextLayout', then measuring it with getLineMetrics(int). This approach will also take fallback fonts into account.
      NOTE: Does not currently support (as in, undefined behavior) multi-line layouts, including those caused by word wrapping. StyledText uses one TextLayout per line and is only affected by word wrap restriction.
      Since:
      3.125
    • setFont Link icon

      public void setFont(Font font)
      Sets the default font which will be used by the receiver to draw and measure text. If the argument is null, then a default font appropriate for the platform will be used instead. Note that a text style can override the default font.
      Parameters:
      font - the new font for the receiver, or null to indicate a default font
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the font has been disposed
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • setIndent Link icon

      public void setIndent(int indent)
      Sets the indent of the receiver. This indent is applied to the first line of each paragraph.
      Parameters:
      indent - new indent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.2
      See Also:
    • setJustify Link icon

      public void setJustify(boolean justify)
      Sets the justification of the receiver. Note that the receiver's width must be set in order to use justification.
      Parameters:
      justify - new justify
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.2
    • setOrientation Link icon

      public void setOrientation(int orientation)
      Sets the orientation of the receiver, which must be one of SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
      Parameters:
      orientation - new orientation style
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • setSegments Link icon

      public void setSegments(int[] segments)
      Sets the offsets of the receiver's text segments. Text segments are used to override the default behavior of the bidirectional algorithm. Bidirectional reordering can happen within a text segment but not between two adjacent segments.

      Each text segment is determined by two consecutive offsets in the segments arrays. The first element of the array should always be zero and the last one should always be equals to length of the text.

      When segments characters are set, the segments are the offsets where the characters are inserted in the text.

      Parameters:
      segments - the text segments offset
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • setSegmentsChars Link icon

      public void setSegmentsChars(char[] segmentsChars)
      Sets the characters to be used in the segments boundaries. The segments are set by calling setSegments(int[]). The application can use this API to insert Unicode Control Characters in the text to control the display of the text and bidi reordering. The characters are not accessible by any other API in TextLayout.
      Parameters:
      segmentsChars - the segments characters
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.6
      See Also:
    • setSpacing Link icon

      public void setSpacing(int spacing)
      Sets the line spacing of the receiver. The line spacing is the space left between lines.
      Parameters:
      spacing - the new line spacing
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the spacing is negative
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • setVerticalIndent Link icon

      public void setVerticalIndent(int verticalIndent)
      Sets the vertical indent of the receiver. The vertical indent is the space left before the first line.
      Parameters:
      verticalIndent - the new vertical indent
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the vertical indent is negative
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.109
    • setStyle Link icon

      public void setStyle(TextStyle style, int start, int end)
      Sets the style of the receiver for the specified range. Styles previously set for that range will be overwritten. The start and end offsets are inclusive and will be clamped if out of range.
      Parameters:
      style - the style
      start - the start offset
      end - the end offset
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • setTabs Link icon

      public void setTabs(int[] tabs)
      Sets the receiver's tab list. Each value in the tab list specifies the space in points from the origin of the text layout to the respective tab stop. The last tab stop width is repeated continuously.
      Parameters:
      tabs - the new tab list
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • setText Link icon

      public void setText(String text)
      Sets the receiver's text.

      Note: Setting the text also clears all the styles. This method returns without doing anything if the new text is the same as the current text.

      Parameters:
      text - the new text
      Throws:
      IllegalArgumentException -
      • ERROR_NULL_ARGUMENT - if the text is null
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • setTextDirection Link icon

      public void setTextDirection(int textDirection)
      Sets the text direction of the receiver, which must be one of SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT or SWT.AUTO_TEXT_DIRECTION.

      Warning: This API is currently only implemented on Windows. It doesn't set the base text direction on GTK and Cocoa.

      Parameters:
      textDirection - the new text direction
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.103
    • setWidth Link icon

      public void setWidth(int width)
      Sets the line width of the receiver, which determines how text should be wrapped and aligned. The default value is -1 which means wrapping is disabled.
      Parameters:
      width - the new width
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the width is 0 or less than -1
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      See Also:
    • setWrapIndent Link icon

      public void setWrapIndent(int wrapIndent)
      Sets the wrap indent of the receiver. This indent is applied to all lines in the paragraph except the first line.
      Parameters:
      wrapIndent - new wrap indent
      Throws:
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.6
      See Also:
    • toString Link icon

      public String toString()
      Returns a string containing a concise, human-readable description of the receiver.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the receiver
    • setDefaultTabWidth Link icon

      public void setDefaultTabWidth(int tabLength)
      Sets Default Tab Width in terms if number of space characters.
      Parameters:
      tabLength - in number of characters
      Throws:
      IllegalArgumentException -
      • ERROR_INVALID_ARGUMENT - if the tabLength is less than 0
      SWTException -
      • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
      Since:
      3.107
      Restriction:
      This method is not intended to be referenced by clients. DO NOT USE This might be removed in 4.8