java.awt
Class TextComponent
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.TextComponent
All Implemented Interfaces:
Serializable, ImageObserver, MenuContainer, Serializable
This class provides common functionality for widgets than
contain text.
Author:- Aaron M. Renn (arenn@urbanophile.com)
textListener
protected transient TextListener textListener
A list of listeners that will receive events from this object.
addTextListener
public synchronized void addTextListener(java.awt.event.TextListener listener)
Adds a new listener to the list of text listeners for this
component.
Parameters:
getCaretPosition
public synchronized int getCaretPosition()
Returns the current caret position in the text.
Returns:
- The caret position in the text.
getListeners
public EventListener[] getListeners(java.lang.Class listenerType)
Returns an array of all the objects currently registered as FooListeners
upon this TextComponent
. FooListeners are registered using
the addFooListener method.
Parameters:
Throws:
ClassCastException
- If listenerType doesn't specify a class or
interface that implements java.util.EventListener.
getSelectedText
public synchronized String getSelectedText()
Returns a string that contains the text that is currently selected.
Returns:
- The currently selected text region.
getSelectionEnd
public synchronized int getSelectionEnd()
Returns the ending position of the selected text region.
// FIXME: What is returned if there is no selected text.
Returns:
- The ending position of the selected text region.
getSelectionStart
public synchronized int getSelectionStart()
Returns the starting position of the selected text region.
// FIXME: What is returned if there is no selected text?
Returns:
- The starting position of the selected text region.
getText
public synchronized String getText()
Returns the text in this component
Returns:
- The text in this component.
getTextListeners
public TextListener[] getTextListeners()
Returns all text listeners registered to this object.
isEditable
public boolean isEditable()
Tests whether or not this component's text can be edited.
Returns:
true
if the text can be edited, false
otherwise.
paramString
protected String paramString()
Returns a debugging string.
Returns:
processEvent
protected void processEvent(java.awt.AWTEvent event)
Processes the specified event for this component. Text events are
processed by calling the processTextEvent()
method.
All other events are passed to the superclass method.
Parameters:
processTextEvent
protected void processTextEvent(java.awt.event.TextEvent event)
Processes the specified text event by dispatching it to any listeners
that are registered. Note that this method will only be called
if text event's are enabled. This will be true if there are any
registered listeners, or if the event has been specifically
enabled using enableEvents()
.
Parameters:
removeNotify
public void removeNotify()
Notifies the component that it should destroy its native peer.
removeTextListener
public synchronized void removeTextListener(java.awt.event.TextListener listener)
Removes the specified listener from the list of listeners
for this component.
Parameters:
select
public synchronized void select(int selectionStart, int endSelection)
This method sets the selected text range to the text between the
specified start and end positions. Illegal values for these
positions are silently fixed.
Parameters:
selectAll
public synchronized void selectAll()
Selects all of the text in the component.
setCaretPosition
public synchronized void setCaretPosition(int caretPosition)
Sets the caret position to the specified value.
Since:Parameters:
Throws:
setEditable
public synchronized void setEditable(boolean editable)
Sets whether or not this component's text can be edited.
Parameters:
setSelectionEnd
public synchronized void setSelectionEnd(int selectionEnd)
Sets the ending position of the selected region to the
specified value. If the specified value is out of range, then it
will be silently changed to the nearest legal value.
Parameters:
setSelectionStart
public synchronized void setSelectionStart(int selectionStart)
Sets the starting position of the selected region to the
specified value. If the specified value is out of range, then it
will be silently changed to the nearest legal value.
Parameters:
setText
public synchronized void setText(java.lang.String text)
Sets the text in this component to the specified string.
Parameters: