Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.awt

Class TextComponent

java.lang.Object
|
+--java.awt.Component
   |
   +--java.awt.TextComponent

All Implemented Interfaces:

Serializable, ImageObserver, MenuContainer, Serializable


public class TextComponent

extends Component

implements Serializable

This class provides common functionality for widgets than contain text.

Author:

Field Summary

transient java.awt.event.TextListenertextListener

A list of listeners that will receive events from this object.

Method Summary

synchronized voidaddTextListener(java.awt.event.TextListener listener)

Adds a new listener to the list of text listeners for this component.
synchronized intgetCaretPosition()

Returns the current caret position in the text.
java.util.EventListener[]getListeners(java.lang.Class listenerType)

Returns an array of all the objects currently registered as FooListeners upon this TextComponent.
synchronized java.lang.StringgetSelectedText()

Returns a string that contains the text that is currently selected.
synchronized intgetSelectionEnd()

Returns the ending position of the selected text region.
synchronized intgetSelectionStart()

Returns the starting position of the selected text region.
synchronized java.lang.StringgetText()

Returns the text in this component
java.awt.event.TextListener[]getTextListeners()

Returns all text listeners registered to this object.
booleanisEditable()

Tests whether or not this component's text can be edited.
java.lang.StringparamString()

Returns a debugging string.
voidprocessEvent(java.awt.AWTEvent event)

Processes the specified event for this component.
voidprocessTextEvent(java.awt.event.TextEvent event)

Processes the specified text event by dispatching it to any listeners that are registered.
voidremoveNotify()

Notifies the component that it should destroy its native peer.
synchronized voidremoveTextListener(java.awt.event.TextListener listener)

Removes the specified listener from the list of listeners for this component.
synchronized voidselect(int selectionStart, int endSelection)

This method sets the selected text range to the text between the specified start and end positions.
synchronized voidselectAll()

Selects all of the text in the component.
synchronized voidsetCaretPosition(int caretPosition)

Sets the caret position to the specified value.
synchronized voidsetEditable(boolean editable)

Sets whether or not this component's text can be edited.
synchronized voidsetSelectionEnd(int selectionEnd)

Sets the ending position of the selected region to the specified value.
synchronized voidsetSelectionStart(int selectionStart)

Sets the starting position of the selected region to the specified value.
synchronized voidsetText(java.lang.String text)

Sets the text in this component to the specified string.

Field Details

textListener

protected transient TextListener textListener

A list of listeners that will receive events from this object.


Method Details

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:


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:


getSelectedText

public synchronized String getSelectedText()

Returns a string that contains the text that is currently selected.

Returns:


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:


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:


getText

public synchronized String getText()

Returns the text in this component

Returns:


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:


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: