|
|
|
|
org.eclipse.swt.widgets
Class Text
java.lang.Object
org.eclipse.swt.widgets.Widget
org.eclipse.swt.widgets.Control
org.eclipse.swt.widgets.Scrollable
org.eclipse.swt.widgets.Text
-
All Implemented Interfaces:
-
Adaptable
- public class Text
- extends
Scrollable
Instances of this class are selectable user interface
objects that allow the user to enter and modify text.
-
Styles:
- CENTER, LEFT, MULTI, PASSWORD, SINGLE, RIGHT, READ_ONLY, WRAP
-
Events:
- DefaultSelection, Modify, Verify
Note: Only one of the styles MULTI and SINGLE may be specified.
IMPORTANT: This class is not intended to be subclassed.
Due to limitations of the JavaScript library, the current WRAP behavior
of a MULI line text is always as if WRAP was set.
-
Since:
- 1.0
Field Summary
|
static int
|
LIMIT
The maximum number of characters that can be entered
into a text widget. |
Constructor Summary
|
Text
(
Composite parent,
int style)
Constructs a new instance of this class given its parent
and a style value describing its behavior and appearance. |
Method Summary
|
void
|
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 the ModifyListener
interface. |
void
|
addSelectionListener
(
SelectionListener listener)
Adds the listener to the collection of listeners who will
be notified when the control is selected, by sending
it one of the messages defined in the SelectionListener
interface. |
void
|
addVerifyListener
(
VerifyListener verifyListener)
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. |
void
|
append
(
String string)
Appends a string. |
void
|
clearSelection
()
Clears the selection. |
Point
|
computeSize
(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver. |
Rectangle
|
computeTrim
(int x,
int y,
int width,
int height)
Given a desired client area for the receiver
(as described by the arguments), returns the bounding
rectangle which would be required to produce that client
area. |
Object
|
getAdapter
(
Class adapter)
Implementation of the Adaptable interface. |
int
|
getCharCount
()
Returns the number of characters. |
boolean
|
getEditable
()
Returns the editable state. |
String
|
getLineDelimiter
()
Returns the line delimiter. |
int
|
getLineHeight
()
Returns the height of a line. |
Point
|
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. |
int
|
getSelectionCount
()
Returns the number of selected characters. |
String
|
getSelectionText
()
Gets the selected text, or an empty string if there is no current selection. |
String
|
getText
()
Returns the widget text. |
int
|
getTextLimit
()
Returns the maximum number of characters that the receiver is capable of holding. |
void
|
insert
(
String string)
Inserts a string. |
void
|
removeModifyListener
(
ModifyListener 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. |
void
|
removeVerifyListener
(
VerifyListener verifyListener)
Removes the listener from the collection of listeners who will
be notified when the control is verified. |
void
|
selectAll
()
Selects all the text in the receiver. |
void
|
setEditable
(boolean editable)
Sets the editable state. |
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
|
setText
(
String text)
Sets the contents of the receiver to the given string. |
void
|
setTextLimit
(int textLimit)
Sets the maximum number of characters that the receiver
is capable of holding to be the argument. |
Methods inherited from class org.eclipse.swt.widgets.
Control
|
addControlListener,
addFocusListener,
addKeyListener,
addMouseListener,
addTraverseListener,
computeSize,
forceFocus,
getBackground,
getBackgroundImage,
getBorderWidth,
getBounds,
getCursor,
getEnabled,
getFont,
getForeground,
getLayoutData,
getLocation,
getMenu,
getMonitor,
getParent,
getShell,
getSize,
getToolTipText,
getVisible,
isEnabled,
isFocusControl,
isVisible,
moveAbove,
moveBelow,
pack,
pack,
redraw,
removeControlListener,
removeFocusListener,
removeKeyListener,
removeMouseListener,
removeTraverseListener,
setBackground,
setBackgroundImage,
setBounds,
setBounds,
setCursor,
setEnabled,
setFocus,
setFont,
setForeground,
setLayoutData,
setLocation,
setLocation,
setMenu,
setRedraw,
setSize,
setSize,
setToolTipText,
setVisible,
toControl,
toControl,
toDisplay,
toDisplay
|
Methods inherited from class org.eclipse.swt.widgets.
Widget
|
addDisposeListener,
addListener,
checkSubclass,
checkWidget,
dispose,
getData,
getData,
getDisplay,
getStyle,
isDisposed,
notifyListeners,
removeDisposeListener,
removeListener,
setData,
setData,
toString
|
LIMIT
public static final int LIMIT
- The 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.
-
See Also:
-
Constant Field Values
Text
public Text(
Composite parent,
int style)
- 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 the int "|" operator) two or more
of those SWT 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:
-
SWT.SINGLE ,
SWT.MULTI ,
SWT.READ_ONLY ,
SWT.WRAP ,
Widget.checkSubclass() ,
Widget.getStyle()
getAdapter
public
Object getAdapter(
Class adapter)
-
Description copied from class:
Widget
- Implementation of the
Adaptable interface.
IMPORTANT: This method is not part of the RWT
public API. It is marked public only so that it can be shared
within the packages provided by RWT. It should never be accessed
from application code.
-
-
Specified by:
-
getAdapter
in interface
Adaptable
-
Overrides:
-
getAdapter
in class
Control
-
setText
public void setText(
String text)
- 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.
-
-
Parameters:
-
text - 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
getText
public
String 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
append
public void append(
String string)
- 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
getLineDelimiter
public
String 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
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
setTextLimit
public void setTextLimit(int textLimit)
- 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 than Text.LIMIT sets the
receiver's limit to Text.LIMIT .
-
-
Parameters:
-
textLimit - 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:
-
LIMIT
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 constant Text.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:
-
LIMIT
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
-
Since:
- 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 range -
end - 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
setSelection
public 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.
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
getSelection
public
Point 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. 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
public
String 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
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
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
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
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
insert
public void insert(
String string)
- 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
-
SWTException -
- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
computeSize
public
Point computeSize(int wHint,
int hHint,
boolean changed)
-
Description copied from class:
Control
- Returns the preferred size of the receiver.
The preferred size of a control is the size that it would
best be displayed at. The width hint and height hint arguments
allow the caller to ask a control questions such as "Given a particular
width, how high does the control need to be to show all of the contents?"
To indicate that the caller does not wish to constrain a particular
dimension, the constant SWT.DEFAULT is passed for the hint.
If the changed flag is true , it indicates that the receiver's
contents have changed, therefore any caches that a layout manager
containing the control may have been keeping need to be flushed. When the
control is resized, the changed flag will be false , so layout
manager caches can be retained.
-
-
Overrides:
-
computeSize
in class
Control
-
-
Parameters:
-
wHint - the width hint (can be SWT.DEFAULT ) -
hHint - the height hint (can be SWT.DEFAULT ) -
changed - true if the control's contents have changed, and false otherwise
-
Returns:
- the preferred size of the control.
-
See Also:
-
Layout ,
Control.getBorderWidth() ,
Control.getBounds() ,
Control.getSize() ,
Control.pack(boolean) ,
"computeTrim, getClientArea for controls that implement them"
computeTrim
public
Rectangle computeTrim(int x,
int y,
int width,
int height)
-
Description copied from class:
Scrollable
- Given a desired client area for the receiver
(as described by the arguments), returns the bounding
rectangle which would be required to produce that client
area.
In other words, it returns a rectangle such that, if the
receiver's bounds were set to that rectangle, the area
of the receiver which is capable of displaying data
(that is, not covered by the "trimmings") would be the
rectangle described by the arguments (relative to the
receiver's parent).
-
-
Overrides:
-
computeTrim
in class
Scrollable
-
-
Parameters:
-
x - the desired x coordinate of the client area -
y - the desired y coordinate of the client area -
width - the desired width of the client area -
height - the desired height of the client area
-
Returns:
- the required bounds to produce the given client area
-
See Also:
-
Scrollable.getClientArea()
addSelectionListener
public void addSelectionListener(
SelectionListener listener)
- Adds the listener to the collection of listeners who will
be notified when the control is selected, by sending
it one of the messages defined in the
SelectionListener
interface.
widgetSelected is not called for texts.
widgetDefaultSelected is typically called when ENTER is pressed in a single-line text.
-
-
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:
-
SelectionListener ,
removeSelectionListener(org.eclipse.swt.events.SelectionListener) ,
SelectionEvent
removeSelectionListener
public void removeSelectionListener(
SelectionListener listener)
- Removes the listener from the collection of listeners who will
be notified when the control is selected.
-
-
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:
-
SelectionListener ,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
addModifyListener
public void 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 the
ModifyListener
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:
-
ModifyListener ,
removeModifyListener(org.eclipse.swt.events.ModifyListener)
removeModifyListener
public void removeModifyListener(
ModifyListener listener)
- 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:
-
ModifyListener ,
addModifyListener(org.eclipse.swt.events.ModifyListener)
addVerifyListener
public void addVerifyListener(
VerifyListener verifyListener)
- 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.
-
-
Parameters:
-
verifyListener - 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:
-
VerifyListener ,
removeVerifyListener(org.eclipse.swt.events.VerifyListener)
removeVerifyListener
public void removeVerifyListener(
VerifyListener verifyListener)
- Removes the listener from the collection of listeners who will
be notified when the control is verified.
-
-
Parameters:
-
verifyListener - 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:
-
VerifyListener ,
addVerifyListener(org.eclipse.swt.events.VerifyListener)
Copyright (c) Innoopract Informationssysteme GmbH and others 2002, 2008. All rights reserved.
|
|
|