Interface ITextComponent
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified text event listener to receive text events from this text component.intReturns the position of the text insertion caret.<T extends EventListener>
T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon thisTextComponent.intGets the end position of the selected text in this text component.intGets the start position of the selected text in this text component.getText()Returns the text that is presented by this text component.Returns an array of all the text listeners registered on this text component.booleanIndicates whether or not this text component is editable.voidRemoves the specified text event listener so that it no longer receives text events from this text component Iflisnull, no exception is thrown and no action is performed.voidselect(int selectionStart, int selectionEnd) Selects the text between the specified start and end positions.voidSelects all the text in this text component.voidsetCaretPosition(int position) Sets the position of the text insertion caret.voidsetEditable(boolean b) Sets the flag that determines whether or not this text component is editable.voidsetSelectionEnd(int selectionEnd) Sets the selection end for this text component to the specified position.voidsetSelectionStart(int selectionStart) Sets the selection start for this text component to the specified position.void
-
Method Details
-
setText
-
getText
String getText()Returns the text that is presented by this text component. By default, this is an empty string.- Returns:
- the value of this
TextComponent - See Also:
-
getSelectedText
String getSelectedText() -
isEditable
boolean isEditable()Indicates whether or not this text component is editable.- Returns:
trueif this text component is editable;falseotherwise.- Since:
- JDK1.0
- See Also:
-
setEditable
void setEditable(boolean b) Sets the flag that determines whether or not this text component is editable.If the flag is set to
true, this text component becomes user editable. If the flag is set tofalse, the user cannot change the text of this text component. By default, non-editable text components have a background color of SystemColor.control. This default can be overridden by calling setBackground.- Parameters:
b- a flag indicating whether this text component is user editable.- Since:
- JDK1.0
- See Also:
-
getSelectionStart
int getSelectionStart()Gets the start position of the selected text in this text component.- Returns:
- the start position of the selected text
- See Also:
-
setSelectionStart
void setSelectionStart(int selectionStart) Sets the selection start for this text component to the specified position. The new start point is constrained to be at or before the current selection end. It also cannot be set to less than zero, the beginning of the component's text. If the caller supplies a value forselectionStartthat is out of bounds, the method enforces these constraints silently, and without failure.- Parameters:
selectionStart- the start position of the selected text- Since:
- JDK1.1
- See Also:
-
getSelectionEnd
int getSelectionEnd()Gets the end position of the selected text in this text component.- Returns:
- the end position of the selected text
- See Also:
-
setSelectionEnd
void setSelectionEnd(int selectionEnd) Sets the selection end for this text component to the specified position. The new end point is constrained to be at or after the current selection start. It also cannot be set beyond the end of the component's text. If the caller supplies a value forselectionEndthat is out of bounds, the method enforces these constraints silently, and without failure.- Parameters:
selectionEnd- the end position of the selected text- Since:
- JDK1.1
- See Also:
-
select
void select(int selectionStart, int selectionEnd) Selects the text between the specified start and end positions.This method sets the start and end positions of the selected text, enforcing the restriction that the start position must be greater than or equal to zero. The end position must be greater than or equal to the start position, and less than or equal to the length of the text component's text. The character positions are indexed starting with zero. The length of the selection is
endPosition-startPosition, so the character atendPositionis not selected. If the start and end positions of the selected text are equal, all text is deselected.If the caller supplies values that are inconsistent or out of bounds, the method enforces these constraints silently, and without failure. Specifically, if the start position or end position is greater than the length of the text, it is reset to equal the text length. If the start position is less than zero, it is reset to zero, and if the end position is less than the start position, it is reset to the start position.
- Parameters:
selectionStart- the zero-based index of the first character (charvalue) to be selectedselectionEnd- the zero-based end position of the text to be selected; the character (charvalue) atselectionEndis not selected- See Also:
-
selectAll
void selectAll()Selects all the text in this text component.- See Also:
-
setCaretPosition
void setCaretPosition(int position) Sets the position of the text insertion caret. The caret position is constrained to be between 0 and the last character of the text, inclusive. If the passed-in value is greater than this range, the value is set to the last character (or 0 if theTextComponentcontains no text) and no error is returned. If the passed-in value is less than 0, anIllegalArgumentExceptionis thrown.- Parameters:
position- the position of the text insertion caret- Throws:
IllegalArgumentException- ifpositionis less than zero- Since:
- JDK1.1
-
getCaretPosition
int getCaretPosition()Returns the position of the text insertion caret. The caret position is constrained to be between 0 and the last character of the text, inclusive. If the text or caret have not been set, the default caret position is 0.- Returns:
- the position of the text insertion caret
- Since:
- JDK1.1
- See Also:
-
addTextListener
Adds the specified text event listener to receive text events from this text component. Iflisnull, no exception is thrown and no action is performed.- Parameters:
l- the text event listener- See Also:
-
removeTextListener
Removes the specified text event listener so that it no longer receives text events from this text component Iflisnull, no exception is thrown and no action is performed.- Parameters:
l- the text listener- Since:
- JDK1.1
- See Also:
-
getTextListeners
TextListener[] getTextListeners()Returns an array of all the text listeners registered on this text component.- Returns:
- all of this text component's
TextListeners or an empty array if no text listeners are currently registered - Since:
- 1.4
- See Also:
-
getListeners
Returns an array of all the objects currently registered asFooListeners upon thisTextComponent.FooListeners are registered using theaddFooListenermethod.You can specify the
listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aTextComponenttfor its text listeners with the following code:TextListener[] tls = (TextListener[])(t.getListeners(TextListener.class));
If no such listeners exist, this method returns an empty array.
- Parameters:
listenerType- the type of listeners requested; this parameter should specify an interface that descends fromjava.util.EventListener- Returns:
- an array of all objects registered as
FooListeners on this text component, or an empty array if no such listeners have been added - Throws:
ClassCastException- iflistenerTypedoesn't specify a class or interface that implementsjava.util.EventListener- Since:
- 1.3
- See Also:
-