Class Text
- All Implemented Interfaces:
Drawable
- 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: This class is not intended to be subclassed.
- See Also:
- Restriction:
- This class is not intended to be subclassed by clients.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The delimiter used by multi-line text widgets.static final int
The maximum number of characters that can be entered into a text widget. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addModifyListener
(ModifyListener 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 theModifyListener
interface.void
addSegmentListener
(SegmentListener listener) Adds a segment listener.void
addSelectionListener
(SelectionListener 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 theSelectionListener
interface.void
addVerifyListener
(VerifyListener 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 theVerifyListener
interface.void
Appends a string.void
Clears the selection.void
copy()
Copies the selected text.void
cut()
Cuts the selected text.int
Returns the line number of the caret.Returns a point describing the location of the caret relative to the receiver.int
Returns the character position of the caret.int
Returns the number of characters.boolean
Returns the double click enabled flag.char
Returns the echo character.boolean
Returns the editable state.int
Returns the number of lines.Returns the line delimiter.int
Returns the height of a line.Returns the widget message.int
Returns the orientation of the receiver, which will be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.Returns aPoint
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.int
Returns the number of selected characters.Gets the selected text, or an empty string if there is no current selection.int
getTabs()
Returns the number of tabs.getText()
Returns the widget text.getText
(int start, int end) Returns a range of text.char[]
Returns the widget's text as a character array.int
Returns the maximum number of characters that the receiver is capable of holding.int
Returns the zero-relative index of the line which is currently at the top of the receiver.int
Returns the top SWT logical point.void
Inserts a string.void
paste()
Pastes text from clipboard.void
removeModifyListener
(ModifyListener listener) Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.void
removeSegmentListener
(SegmentListener listener) Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.void
removeSelectionListener
(SelectionListener listener) Removes the listener from the collection of listeners who will be notified when the control is selected by the user.void
removeVerifyListener
(VerifyListener listener) Removes the listener from the collection of listeners who will be notified when the control is verified.void
Selects all the text in the receiver.void
setDoubleClickEnabled
(boolean doubleClick) Sets the double click enabled flag.void
setEchoChar
(char echo) Sets the echo character.void
setEditable
(boolean editable) Sets the editable state.void
Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null.void
setMessage
(String message) Sets the widget message.void
setOrientation
(int orientation) Sets the orientation of the receiver, which must be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.void
setRedraw
(boolean redraw) If the argument isfalse
, causes subsequent drawing operations in the receiver to be ignored.void
setSelection
(int start) Sets the selection.void
setSelection
(int start, int end) Sets the selection to the range specified by the given start and end indices.void
setSelection
(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.void
setTabs
(int tabs) Sets the number of tabs.void
Sets the contents of the receiver to the given string.void
setTextChars
(char[] text) Sets the contents of the receiver to the characters in the array.void
setTextLimit
(int limit) Sets the maximum number of characters that the receiver is capable of holding to be the argument.void
setTopIndex
(int index) Sets the zero-relative index of the line which is currently at the top of the receiver.void
Shows the selection.Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar, setScrollbarsMode
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFocus, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, addTypedListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, getTypedListeners, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, removeTypedListener, reskin, setData, setData, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.swt.graphics.Drawable
isAutoScalable
-
Field Details
-
LIMIT
public static final int LIMITThe maximum number of characters that can be entered into a text widget.Note that this value is platform dependent, based upon the native widget implementation.
-
DELIMITER
The delimiter used by multi-line text widgets. When text is queried and from the widget, it will be delimited using this delimiter.
-
-
Constructor Details
-
Text
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to construct- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
-
-
Method Details
-
addModifyListener
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 theModifyListener
interface.- Parameters:
listener
- the listener which should be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
addSegmentListener
Adds a segment listener.A
SegmentEvent
is sent whenever text content is being modified or a segment listener is added or removed. You can customize the appearance of text by indicating certain characters to be inserted at certain text offsets. This may be used for bidi purposes, e.g. when adjacent segments of right-to-left text should not be reordered relative to each other. E.g., multiple Java string literals in a right-to-left language should generally remain in logical order to each other, that is, the way they are stored.Warning: This API is currently only implemented on Windows and GTK.
SegmentEvent
s won't be sent on Cocoa.- Parameters:
listener
- the listener which should be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.8
- See Also:
-
addSelectionListener
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 theSelectionListener
interface.widgetSelected
is not called for texts.widgetDefaultSelected
is typically called when ENTER is pressed in a single-line text, or when ENTER is pressed in a search text. If the receiver has theSWT.SEARCH | SWT.ICON_CANCEL
style and the user cancels the search, the event object detail field contains the valueSWT.ICON_CANCEL
. Likewise, if the receiver has theSWT.ICON_SEARCH
style and the icon search is selected, the event object detail field contains the valueSWT.ICON_SEARCH
.- Parameters:
listener
- the listener which should be notified when the control is selected by the user- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
addVerifyListener
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 theVerifyListener
interface.- Parameters:
listener
- the listener which should be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
append
Appends a string.The new text is appended to the text at the end of the widget.
- Parameters:
string
- the string to be appended- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the string is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
clearSelection
public void clearSelection()Clears the selection.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
copy
public void copy()Copies the selected text.The current selection is copied to the clipboard.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
cut
public void cut()Cuts the selected text.The current selection is first copied to the clipboard and then deleted from the widget.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getCaretLineNumber
public int getCaretLineNumber()Returns the line number of the caret.The line number of the caret is returned.
- Returns:
- the line number
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getCaretLocation
Returns a point describing the location of the caret relative to the receiver.- Returns:
- a point, the location of the caret
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getCaretPosition
public int getCaretPosition()Returns the character position of the caret.Indexing is zero based.
- Returns:
- the position of the caret
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getCharCount
public int getCharCount()Returns the number of characters.- Returns:
- number of characters in the widget
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getDoubleClickEnabled
public boolean getDoubleClickEnabled()Returns the double click enabled flag.The double click flag enables or disables the default action of the text widget when the user double clicks.
- Returns:
- whether or not double click is enabled
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getEchoChar
public char getEchoChar()Returns the echo character.The echo character is the character that is displayed when the user enters text or the text is changed by the programmer.
- Returns:
- the echo character
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getEditable
public boolean getEditable()Returns the editable state.- Returns:
- whether or not the receiver is editable
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getLineCount
public int getLineCount()Returns the number of lines.- Returns:
- the number of lines in the widget
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getLineDelimiter
Returns the line delimiter.- Returns:
- a string that is the line delimiter
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getLineHeight
public int getLineHeight()Returns the height of a line.- Returns:
- the height of a row of text
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getOrientation
public int getOrientation()Returns the orientation of the receiver, which will be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.- Overrides:
getOrientation
in classControl
- Returns:
- the orientation style
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 2.1.2
-
getMessage
Returns the widget message. The message text is displayed as a hint for the user, indicating the purpose of the field.Typically this is used in conjunction with
SWT.SEARCH
.- Returns:
- the widget message
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.3
-
getSelection
Returns aPoint
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. An "empty" selection is indicated by the x and y coordinates having the same value.Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
- Returns:
- a point representing the selection start and end
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelectionCount
public int getSelectionCount()Returns the number of selected characters.- Returns:
- the number of selected characters.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelectionText
Gets the selected text, or an empty string if there is no current selection.- Returns:
- the selected text
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getTabs
public int getTabs()Returns the number of tabs.Tab stop spacing is specified in terms of the space (' ') character. The width of a single tab stop is the pixel width of the spaces.
- Returns:
- the number of tab characters
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getText
Returns the widget text.The text for a text widget is the characters in the widget, or an empty string if this has never been set.
- Returns:
- the widget text
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getTextChars
public char[] getTextChars()Returns the widget's text as a character array.The text for a text widget is the characters in the widget, or a zero-length array if this has never been set.
Note: Use this API to prevent the text from being written into a String object whose lifecycle is outside of your control. This can help protect the text, for example, when the widget is used as a password field. However, the text can't be protected if an
SWT.Segments
orSWT.Verify
listener has been added to the widget.- Returns:
- a character array that contains the widget's text
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.7
- See Also:
-
getText
Returns a range of text. Returns an empty string if the start of the range is greater than the end.Indexing is zero based. The range of a selection is from 0..N-1 where N is the number of characters in the widget.
- Parameters:
start
- the start of the rangeend
- the end of the range- Returns:
- the range of text
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getTextLimit
public int getTextLimit()Returns the maximum number of characters that the receiver is capable of holding.If this has not been changed by
setTextLimit()
, it will be the constantText.LIMIT
.- Returns:
- the text limit
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
getTopIndex
public int getTopIndex()Returns the zero-relative index of the line which is currently at the top of the receiver.This index can change when lines are scrolled or new lines are added or removed.
- Returns:
- the index of the top line
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getTopPixel
public int getTopPixel()Returns the top SWT logical point.The top point is the SWT logical point position of the line that is currently at the top of the widget. On some platforms, a text widget can be scrolled by points instead of lines so that a partial line is displayed at the top of the widget.
The top SWT logical point changes when the widget is scrolled. The top SWT logical point does not include the widget trimming.
- Returns:
- the SWT logical point position of the top line
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
insert
Inserts a string.The old selection is replaced with the new text.
- Parameters:
string
- the string- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the string is
null
- ERROR_NULL_ARGUMENT - if the string is
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
paste
public void paste()Pastes text from clipboard.The selected text is deleted from the widget and new text inserted from the clipboard.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
removeModifyListener
Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
removeSegmentListener
Removes the listener from the collection of listeners who will be notified when the receiver's text is modified.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.8
- See Also:
-
removeSelectionListener
Removes the listener from the collection of listeners who will be notified when the control is selected by the user.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
removeVerifyListener
Removes the listener from the collection of listeners who will be notified when the control is verified.- Parameters:
listener
- the listener which should no longer be notified- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
selectAll
public void selectAll()Selects all the text in the receiver.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setDoubleClickEnabled
public void setDoubleClickEnabled(boolean doubleClick) Sets the double click enabled flag.The double click flag enables or disables the default action of the text widget when the user double clicks.
Note: This operation is a hint and is not supported on platforms that do not have this concept.
- Parameters:
doubleClick
- the new double click flag- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setEchoChar
public void setEchoChar(char echo) Sets the echo character.The echo character is the character that is displayed when the user enters text or the text is changed by the programmer. Setting the echo character to '\0' clears the echo character and redraws the original text. If for any reason the echo character is invalid, or if the platform does not allow modification of the echo character, the default echo character for the platform is used.
- Parameters:
echo
- the new echo character- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setEditable
public void setEditable(boolean editable) Sets the editable state.- Parameters:
editable
- the new editable state- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setFont
Description copied from class:Control
Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null. -
setMessage
Sets the widget message. The message text is displayed as a hint for the user, indicating the purpose of the field.Typically this is used in conjunction with
SWT.SEARCH
.- Parameters:
message
- the new message- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the message is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.3
-
setOrientation
public void setOrientation(int orientation) Sets the orientation of the receiver, which must be one of the constantsSWT.LEFT_TO_RIGHT
orSWT.RIGHT_TO_LEFT
.Note: This operation is a hint and is not supported on platforms that do not have this concept.
- Overrides:
setOrientation
in classControl
- Parameters:
orientation
- new orientation style- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 2.1.2
-
setSelection
public void setSelection(int start) Sets the selection.Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N. This differs from other functions that address character position such as getText () that use the regular array indexing rules.
- Parameters:
start
- new caret position- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSelection
public void setSelection(int start, int end) Sets the selection to the range specified by the given start and end indices.Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N. This differs from other functions that address character position such as getText () that use the usual array indexing rules.
- Parameters:
start
- the start of the rangeend
- the end of the range- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setRedraw
public void setRedraw(boolean redraw) Description copied from class:Control
If the argument isfalse
, causes subsequent drawing operations in the receiver to be ignored. No drawing of any kind can occur in the receiver until the flag is set to true. Graphics operations that occurred while the flag wasfalse
are lost. When the flag is set totrue
, the entire widget is marked as needing to be redrawn. Nested calls to this method are stacked.Note: This operation is a hint and may not be supported on some platforms or for some widgets.
-
setSelection
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.Indexing is zero based. The range of a selection is from 0..N where N is the number of characters in the widget.
Text selections are specified in terms of caret positions. In a text widget that contains N characters, there are N+1 caret positions, ranging from 0..N. This differs from other functions that address character position such as getText () that use the usual array indexing rules.
- Parameters:
selection
- the point- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the point is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setTabs
public void setTabs(int tabs) Sets the number of tabs.Tab stop spacing is specified in terms of the space (' ') character. The width of a single tab stop is the pixel width of the spaces.
- Parameters:
tabs
- the number of tabs- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setText
Sets the contents of the receiver to the given string. If the receiver has style SINGLE and the argument contains multiple lines of text, the result of this operation is undefined and may vary from platform to platform.Note: If control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.
- Parameters:
string
- the new text- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the string is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setTextChars
public void setTextChars(char[] text) Sets the contents of the receiver to the characters in the array. If the receiver has styleSWT.SINGLE
and the argument contains multiple lines of text then the result of this operation is undefined and may vary between platforms.Note: Use this API to prevent the text from being written into a String object whose lifecycle is outside of your control. This can help protect the text, for example, when the widget is used as a password field. However, the text can't be protected if an
SWT.Segments
orSWT.Verify
listener has been added to the widget.- Parameters:
text
- a character array that contains the new text- Throws:
IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the array is null
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.7
- See Also:
-
setTextLimit
public void setTextLimit(int limit) Sets the maximum number of characters that the receiver is capable of holding to be the argument.Instead of trying to set the text limit to zero, consider creating a read-only text widget.
To reset this value to the default, use
setTextLimit(Text.LIMIT)
. Specifying a limit value larger thanText.LIMIT
sets the receiver's limit toText.LIMIT
.- Parameters:
limit
- new text limit- Throws:
IllegalArgumentException
-- ERROR_CANNOT_BE_ZERO - if the limit is zero
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
-
setTopIndex
public void setTopIndex(int index) Sets the zero-relative index of the line which is currently at the top of the receiver. This index can change when lines are scrolled or new lines are added and removed.- Parameters:
index
- the index of the top item- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
showSelection
public void showSelection()Shows the selection.If the selection is already showing in the receiver, this method simply returns. Otherwise, lines are scrolled until the selection is visible.
- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-