Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public Class Text

extends Scrollable
Class Inheritance
Imports
java.util.*, org.eclipse.swt.*, org.eclipse.swt.events.*, org.eclipse.swt.graphics.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

Instances of this class are selectable user interface objects that allow the user to enter and modify text. Text controls can be either single or multi-line. When a text control is created with a border, the operating system includes a platform specific inset around the contents of the control. When created without a border, an effort is made to remove the inset such that the preferred size of the control is the same size as the contents.
Styles:
CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP
Events:
DefaultSelection, Modify, Verify, OrientationChange

Note

Only one of the styles MULTI and SINGLE may be specified, and only one of the styles LEFT, CENTER, and RIGHT may be specified.

Note

The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH. When the platform supports the hint, the text control shows these icons. When an icon is selected, a default selection event is sent with the detail field set to one of ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the detail. In the case of ICON_CANCEL, the text is cleared before the default selection event is sent causing the application to search for an empty string.

Note

Some text actions such as Undo are not natively supported on all platforms.

Important Note

This class is not intended to be subclassed.

See Also
Text snippets, SWT Example: ControlExample, Sample code and further information

Field Summary

Modifier and TypeField and Description
pack-priv GdkRGBA
pack-priv long
pack-priv double
pack-priv double
public static final String
DELIMITER

The delimiter used by multi-line text widgets.

pack-priv boolean
pack-priv int
pack-priv int
pack-priv GdkRGBA
pack-priv long
pack-priv long
pack-priv long
pack-priv static final int
pack-priv int
public static final int
LIMIT

The maximum number of characters that can be entered into a text widget.

pack-priv static final char
pack-priv String
pack-priv static final char
pack-priv int[]
pack-priv static final int
pack-priv int
pack-priv long
textHandle

GTK4 only field, holds the address to the underlying GtkText widget.

Inherited from org.eclipse.swt.widgets.Scrollable:
horizontalBarRESIZE_ON_GETCLIENTAREAscrolledHandleverticalBar

Constructor Summary

AccessConstructor and Description
public
Text(Composite
a composite control which will be the parent of the new instance (cannot be null)
parent
,
int
the style of control to construct
style
)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Method Summary

Modifier and TypeMethod and Description
public void
addModifyListener(ModifyListener
the listener which should be notified
listener
)

Adds the listener to the collection of listeners who will be notified when the receiver's text is modified, by sending it one of the messages defined in the ModifyListener interface.

public void
addSegmentListener(SegmentListener
the listener which should be notified
listener
)

Adds a segment listener.

public void
addSelectionListener(SelectionListener
the listener which should be notified when the control is selected by the user
listener
)

Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in the SelectionListener interface.

public void
addVerifyListener(VerifyListener
the listener which should be notified
listener
)

Adds the listener to the collection of listeners who will be notified when the receiver's text is verified, by sending it one of the messages defined in the VerifyListener interface.

public void
append(String
the string to be appended
string
)

Appends a string.

pack-priv void
pack-priv int
pack-priv static int
checkStyle(int style)

pack-priv void
clearSegments(boolean applyText)

public void
clearSelection()

Clears the selection.

pack-priv Point
computeSizeInPixels(int wHint, int hHint, boolean changed)

Overrides org.eclipse.swt.widgets.Control.computeSizeInPixels.

pack-priv Rectangle
computeTrimInPixels(int x, int y, int width, int height)

Overrides org.eclipse.swt.widgets.Scrollable.computeTrimInPixels.

public void
copy()

Copies the selected text.

pack-priv void
pack-priv void
public void
cut()

Cuts the selected text.

pack-priv GdkRGBA
pack-priv char[]
deprocessText(char[] text, int start, int end)

pack-priv void
pack-priv boolean
dragDetect(int x, int y, boolean filter, boolean dragOnTimeout, boolean[] consume)

Overrides org.eclipse.swt.widgets.Control.dragDetect.

pack-priv long
pack-priv boolean
pack-priv void
pack-priv int
public int

Returns:

the line number
getCaretLineNumber
()

Returns the line number of the caret.

public Point

Returns:

a point, the location of the caret
getCaretLocation
()

Returns a point describing the location of the caret relative to the receiver.

pack-priv Point
public int

Returns:

the position of the caret
getCaretPosition
()

Returns the character position of the caret.

public int

Returns:

number of characters in the widget
getCharCount
()

Returns the number of characters.

pack-priv GdkRGBA
pack-priv GdkRGBA
public boolean

Returns:

whether or not double click is enabled
getDoubleClickEnabled
()

Returns the double click enabled flag.

public char

Returns:

the echo character
getEchoChar
()

Returns the echo character.

public boolean

Returns:

whether or not the receiver is editable
getEditable
()

Returns the editable state.

public int

Returns:

the number of lines in the widget
getLineCount
()

Returns the number of lines.

public String

Returns:

a string that is the line delimiter
getLineDelimiter
()

Returns the line delimiter.

public int

Returns:

the height of a row of text
getLineHeight
()

Returns the height of a line.

public String

Returns:

the widget message
getMessage
()

Returns the widget message.

public int

Returns:

the orientation style
getOrientation
()

Overrides org.eclipse.swt.widgets.Control.getOrientation.

Returns the orientation of the receiver, which will be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
pack-priv int
public Point

Returns:

a point representing the selection start and end
getSelection
()

Returns a Point whose x coordinate is the character position representing the start of the selected text, and whose y coordinate is the character position representing the end of the selection.

public int

Returns:

the number of selected characters.
getSelectionCount
()

Returns the number of selected characters.

public String

Returns:

the selected text
getSelectionText
()

Gets the selected text, or an empty string if there is no current selection.

public int

Returns:

the number of tab characters
getTabs
()

Returns the number of tabs.

pack-priv int
getTabWidth(int tabs)

public String

Returns:

the widget text
getText
()

Returns the widget text.

public String

Returns:

the range of text
getText
(int
the start of the range
start
,
int
the end of the range
end
)

Returns a range of text.

public char[]

Returns:

a character array that contains the widget's text
getTextChars
()

Returns the widget's text as a character array.

public int

Returns:

the text limit
getTextLimit
()

Returns the maximum number of characters that the receiver is capable of holding.

public int

Returns:

the index of the top line
getTopIndex
()

Returns the zero-relative index of the line which is currently at the top of the receiver.

public int

Returns:

the SWT logical point position of the top line
getTopPixel
()

Returns the top SWT logical point.

pack-priv int
pack-priv long
pack-priv long
pack-priv long
pack-priv long
gtk_commit(long imContext, long text)

Overrides org.eclipse.swt.widgets.Control.gtk_commit.

pack-priv long
gtk_delete_range(long widget, long iter1, long iter2)

Overrides org.eclipse.swt.widgets.Widget.gtk_delete_range.

pack-priv long
gtk_delete_text(long widget, long start_pos, long end_pos)

Overrides org.eclipse.swt.widgets.Widget.gtk_delete_text.

pack-priv long
gtk_draw(long widget, long cairo)

Overrides org.eclipse.swt.widgets.Scrollable.gtk_draw.

pack-priv long
pack-priv long
pack-priv long
pack-priv long
gtk_icon_release(long widget, long icon_pos, long event)

Overrides org.eclipse.swt.widgets.Widget.gtk_icon_release.

pack-priv long
gtk_insert_text(long widget, long new_text, long new_text_length, long position)

Overrides org.eclipse.swt.widgets.Widget.gtk_insert_text.

pack-priv long
pack-priv long
pack-priv long
gtk_text_buffer_insert_text(long widget, long iter, long text, long length)

Overrides org.eclipse.swt.widgets.Widget.gtk_text_buffer_insert_text.

pack-priv void
public void
insert(String
the string
string
)

Inserts a string.

pack-priv boolean
mustBeVisibleOnInitBounds()

Overrides org.eclipse.swt.widgets.Control.mustBeVisibleOnInitBounds.

Widgets with unusual bounds calculation behavior can override this method to return true if the widget must be visible during call to setInitialBounds().
pack-priv long
public void
paste()

Pastes text from clipboard.

pack-priv void
pack-priv void
public void
removeModifyListener(ModifyListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.

public void
removeSegmentListener(SegmentListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.

public void
removeSelectionListener(SelectionListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the control is selected by the user.

public void
removeVerifyListener(VerifyListener
the listener which should no longer be notified
listener
)

Removes the listener from the collection of listeners who will be notified when the control is verified.

private void
scrollIfNotVisible(byte[]
the GtkTextIter representing the insertion/selection point
iter
,
byte[]
the GtkTextIter representing the point to be scrolled to (can be null)
scrollTo
,
boolean
true if insertion is being performed, false if selection
insert
)

Methods that insert or select text should not modify the topIndex of the viewer.

public void
selectAll()

Selects all the text in the receiver.

pack-priv void
pack-priv void
public void
setDoubleClickEnabled(boolean
the new double click flag
doubleClick
)

Sets the double click enabled flag.

public void
setEchoChar(char
the new echo character
echo
)

Sets the echo character.

public void
setEditable(boolean
the new editable state
editable
)

Sets the editable state.

pack-priv void
pack-priv void
public void
setMessage(String
the new message
message
)

Sets the widget message.

public void
setOrientation(int
new orientation style
orientation
)

Overrides org.eclipse.swt.widgets.Control.setOrientation.

Sets the orientation of the receiver, which must be one of the constants SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT.
public void
setSelection(int
new caret position
start
)

Sets the selection.

public void
setSelection(int
the start of the range
start
,
int
the end of the range
end
)

Sets the selection to the range specified by the given start and end indices.

public void
setSelection(Point
the point
selection
)

Sets the selection to the range specified by the given point, where the x coordinate represents the start index and the y coordinate represents the end index.

public void
setTabs(int
the number of tabs
tabs
)

Sets the number of tabs.

pack-priv void
setTabStops(int tabs)

public void
setText(String
the new text
string
)

Sets the contents of the receiver to the given string.

pack-priv void
setText(char[] text)

public void
setTextChars(char[]
a character array that contains the new text
text
)

Sets the contents of the receiver to the characters in the array.

public void
setTextLimit(int
new text limit
limit
)

Sets the maximum number of characters that the receiver is capable of holding to be the argument.

public void
setTopIndex(int
the index of the top item
index
)

Sets the zero-relative index of the line which is currently at the top of the receiver.

public void
showSelection()

Shows the selection.

pack-priv int
translateOffset(int offset)

pack-priv boolean
pack-priv int
pack-priv int
untranslateOffset(int offset)

pack-priv String
verifyText(String string, int start, int end)

pack-priv long
windowProc(long handle, long user_data)

Overrides org.eclipse.swt.widgets.Widget.windowProc.

pack-priv long
windowProc(long handle, long arg0, long user_data)

Overrides org.eclipse.swt.widgets.Control.windowProc.

pack-priv long
windowProc(long handle, long arg0, long arg1, long user_data)

Overrides org.eclipse.swt.widgets.Widget.windowProc.

pack-priv long
windowProc(long handle, long arg0, long arg1, long arg2, long user_data)

Overrides org.eclipse.swt.widgets.Widget.windowProc.

Inherited from org.eclipse.swt.widgets.Scrollable:
clientHandlecomputeTrimcreateScrollBardestroyScrollBargetClientAreagetClientAreaInPixelsgetHorizontalBargetScrollbarsModegetVerticalBargtk_scroll_eventhScrollBarWidthredrawBackgroundImageredrawWidgetreleaseChildrenreleaseHandleresizeHandlereskinChildrensendLeaveNotifysetOrientationsetScrollBarVisibleshowWidgettopHandleupdateBackgroundModeupdateScrollBarValuevScrollBarWidth