APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt

public sealed Class TextComponent

extends Component
implements Accessible
permits TextArea, TextField
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible
Known Direct Subclasses
java.awt.TextField, java.awt.TextArea
Imports
java.awt.event.TextEvent, .TextListener, java.awt.im.InputMethodRequests, java.awt.peer.TextComponentPeer, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, java.text.BreakIterator, java.util.EventListener, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole, .AccessibleState, .AccessibleStateSet, .AccessibleText, javax.swing.text.AttributeSet, sun.awt.InputMethodSupport

The TextComponent class is the superclass of any component that allows the editing of some text.

A text component embodies a string of text. The TextComponent class defines a set of methods that determine whether or not this text is editable. If the component is editable, it defines another set of methods that supports a text insertion caret.

In addition, the class defines methods that are used to maintain a current selection from the text. The text selection, a substring of the component's text, is the target of editing operations. It is also referred to as the selected text.

Authors
Sami Shaio, Arthur van Hoff
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
TextComponent.AccessibleAWTTextComponent

This class implements accessibility support for the TextComponent class.

Field Summary

Modifier and TypeField and Description
pack-priv boolean
private boolean
pack-priv boolean
editable

A boolean indicating whether or not this TextComponent is editable.

pack-priv int
selectionEnd

The selection refers to the selected text, and the selectionEnd is the end position of the selected text.

pack-priv int
selectionStart

The selection refers to the selected text, and the selectionStart is the start position of the selected text.

private static final long
serialVersionUID

Hides java.awt.Component.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
pack-priv String
text

The value of the text.

private int
textComponentSerializedDataVersion

The textComponent SerializedDataVersion.

protected transient TextListener
textListener

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

Inherited from java.awt.Component:
accessibleContextactionListenerKadjustmentListenerKbackgroundbackgroundEraseDisabledBOTTOM_ALIGNMENTCENTER_ALIGNMENTcomponentListenercomponentListenerKcomponentOrientationcontainerListenerKcursordropTargetenabledeventCacheeventMaskfocusListenerfocusListenerKfocusTraversalKeysfontforegroundheighthierarchyBoundsListenerhierarchyBoundsListenerKhierarchyListenerhierarchyListenerKignoreRepaintincRateinputMethodListenerinputMethodListenerKisIncisPackeditemListenerKkeyListenerkeyListenerKLEFT_ALIGNMENTlocaleLOCKmaxSizemaxSizeSetminSizeminSizeSetmouseListenermouseListenerKmouseMotionListenermouseMotionListenerKmouseWheelListenermouseWheelListenerKnewEventsOnlyownedWindowKparentpeerpeerFontpopupsprefSizeprefSizeSetRIGHT_ALIGNMENTtextListenerKTOP_ALIGNMENTvisiblewidthwindowFocusListenerKwindowListenerKwindowStateListenerKxy

Constructor Summary

AccessConstructor and Description
pack-priv
TextComponent(String
the text to be displayed; if text is null, the empty string "" will be displayed
text
)

Constructs a new text component initialized with the specified text.

Method Summary

Modifier and TypeMethod and Description
public void
addNotify()

Overrides java.awt.Component.addNotify.

Makes this Component displayable by connecting it to a native screen resource.

public synchronized void
addTextListener(TextListener
the text event listener
l
)

Adds the specified text event listener to receive text events from this text component.

pack-priv boolean
public void
enableInputMethods(boolean
true to enable, false to disable
enable
)

Overrides java.awt.Component.enableInputMethods.

Enables or disables input method support for this text component.

private void
pack-priv boolean
public AccessibleContext

Returns:

an AccessibleAWTTextComponent that serves as the AccessibleContext of this TextComponent
getAccessibleContext
()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this TextComponent.

public Color

Returns:

This text component's background color. If this text component does not have a background color, the background color of its parent is returned.
getBackground
()

Overrides java.awt.Component.getBackground.

Gets the background color of this text component.

public synchronized int

Returns:

the position of the text insertion caret
getCaretPosition
()

Returns the position of the text insertion caret.

public InputMethodRequests
getInputMethodRequests()

Overrides java.awt.Component.getInputMethodRequests.

Gets the input method request handler which supports requests from input methods for this component.

public <T extends EventListener> T[]

Returns:

an array of all objects registered as FooListeners on this text component, or an empty array if no such listeners have been added
getListeners
(Class<T>
the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
listenerType
)

Overrides java.awt.Component.getListeners.

Returns an array of all the objects currently registered as FooListeners upon this TextComponent.

public synchronized String

Returns:

the selected text of this text component
getSelectedText
()

Returns the selected text from the text that is presented by this text component.

public synchronized int

Returns:

the end position of the selected text
getSelectionEnd
()

Gets the end position of the selected text in this text component.

public synchronized int

Returns:

the start position of the selected text
getSelectionStart
()

Gets the start position of the selected text in this text component.

public synchronized String

Returns:

the value of this TextComponent
getText
()

Returns the text that is presented by this text component.

public synchronized TextListener[]

Returns:

all of this text component's TextListeners or an empty array if no text listeners are currently registered
getTextListeners
()

Returns an array of all the text listeners registered on this text component.

public boolean

Returns:

true if this text component is editable; false otherwise.
isEditable
()

Indicates whether or not this text component is editable.

protected String

Returns:

the parameter string of this text component
paramString
()

Overrides java.awt.Component.paramString.

Returns a string representing the state of this TextComponent.

protected void
processEvent(AWTEvent
the event
e
)

Overrides java.awt.Component.processEvent.

Processes events on this text component.

protected void
processTextEvent(TextEvent
the text event
e
)

Processes text events occurring on this text component by dispatching them to any registered TextListener objects.

private void
readObject(ObjectInputStream
the ObjectInputStream to read
s
)

Hides java.awt.Component.readObject.

Read the ObjectInputStream, and if it isn't null, add a listener to receive text events fired by the TextComponent.

public void
removeNotify()

Overrides java.awt.Component.removeNotify.

Removes the TextComponent's peer.

public synchronized void
removeTextListener(TextListener
the text listener
l
)

Removes the specified text event listener so that it no longer receives text events from this text component If l is null, no exception is thrown and no action is performed.

public synchronized void
select(int
the zero-based index of the first character (char value) to be selected
selectionStart
,
int
the zero-based end position of the text to be selected; the character (char value) at selectionEnd is not selected
selectionEnd
)

Selects the text between the specified start and end positions.

public synchronized void
selectAll()

Selects all the text in this text component.

public void
setBackground(Color
The color to become this text component's color. If this parameter is null then this text component will inherit the background color of its parent.
c
)

Overrides java.awt.Component.setBackground.

Sets the background color of this text component.

public synchronized void
setCaretPosition(int
the position of the text insertion caret
position
)

Sets the position of the text insertion caret.

public synchronized void
setEditable(boolean
a flag indicating whether this text component is user editable.
b
)

Sets the flag that determines whether or not this text component is editable.

public synchronized void
setSelectionEnd(int
the end position of the selected text
selectionEnd
)

Sets the selection end for this text component to the specified position.

public synchronized void
setSelectionStart(int
the start position of the selected text
selectionStart
)

Sets the selection start for this text component to the specified position.

public synchronized void
setText(String
the new text; if this parameter is null then the text is set to the empty string ""
t
)

Sets the text that is presented by this text component to be the specified text.

private void
writeObject(ObjectOutputStream
the ObjectOutputStream to write
s
)

Hides java.awt.Component.writeObject.

Writes default serializable fields to stream.

Inherited from java.awt.Component:
actionaddaddComponentListeneraddFocusListeneraddHierarchyBoundsListeneraddHierarchyListeneraddInputMethodListeneraddKeyListeneraddMouseListeneraddMouseMotionListeneraddMouseWheelListeneraddPropertyChangeListeneraddPropertyChangeListeneradjustListeningChildrenOnParentapplyComponentOrientationapplyCompoundShapeapplyCurrentShapeareBoundsValidareFocusTraversalKeysSetautoProcessMouseWheelboundscanBeFocusOwnercanBeFocusOwnerRecursivelycheckGDcheckImagecheckImagecheckTreeLockclearCurrentFocusCycleRootOnHideclearMostRecentFocusOwnerOnHidecoalesceEventsconstructComponentNamecontainscontainscontainsFocuscountHierarchyMemberscreateBufferStrategycreateBufferStrategycreateHierarchyEventscreateImagecreateImagecreateVolatileImagecreateVolatileImagedeliverEventdisabledisableEventsdispatchEventdispatchEventImpldispatchMouseWheelToAncestordoLayoutenableenableenableEventseventTypeEnabledfindUnderMouseInWindowfirePropertyChangefirePropertyChangefirePropertyChangefirePropertyChangefirePropertyChangefirePropertyChangefirePropertyChangefirePropertyChangefirePropertyChangegetAccessibleIndexInParentgetAccessibleStateSetgetAlignmentXgetAlignmentYgetBackBuffergetBaselinegetBaselineResizeBehaviorgetBoundsgetBoundsgetBoundsOpgetBufferStrategygetColorModelgetComponentAtgetComponentAtgetComponentFactorygetComponentListenersgetComponentOrientationgetContainergetContainingWindowgetCursorgetCursor_NoClientCodegetDropTargetgetFocusCycleRootAncestorgetFocusListenersgetFocusTraversalKeysgetFocusTraversalKeys_NoIDCheckgetFocusTraversalKeysEnabledgetFontgetFont_NoClientCodegetFontMetricsgetForegroundgetGraphicsgetGraphics_NoClientCodegetGraphicsConfigurationgetGraphicsConfiguration_NoClientCodegetHeightgetHierarchyBoundsListenersgetHierarchyListenersgetHWPeerAboveMegetIgnoreRepaintgetInputContextgetInputMethodListenersgetKeyListenersgetLocalegetLocationgetLocationgetLocationOnScreengetLocationOnScreen_NoTreeLockgetLocationOnWindowgetMaximumSizegetMinimumSizegetMouseListenersgetMouseMotionListenersgetMousePositiongetMouseWheelListenersgetNamegetNativeContainergetNextFocusCandidategetNormalShapegetObjectLockgetOpaqueShapegetParentgetParent_NoClientCodegetPreferredSizegetPropertyChangeListenersgetPropertyChangeListenersgetSiblingIndexAbovegetSiblingIndexBelowgetSizegetSizegetToolkitgetToolkitImplgetTraversalRootgetTreeLockgetWidthgetXgetYgotFocushandleEventhasFocushideimageUpdateinitializeFocusTraversalKeysinsideinvalidateinvalidateIfValidinvalidateParentisAutoFocusTransferOnDisposalisBackgroundSetisCoalescingEnabledisCursorSetisDisplayableisDoubleBufferedisEnabledisEnabledImplisFocusableisFocusCycleRootisFocusOwnerisFocusTraversableisFocusTraversableOverriddenisFontSetisForegroundSetisInstanceOfisLightweightisMaximumSizeSetisMinimumSizeSetisMixingNeededisNonOpaqueForMixingisOpaqueisPreferredSizeSetisRecursivelyVisibleisSameOrAncestorOfisShowingisValidisVisibleisVisible_NoClientCodekeyDownkeyUplayoutlightweightPaintlightweightPrintlistlistlistlistlistlocatelocationlostFocusminimumSizemixOnHidingmixOnReshapingmixOnShowingmixOnValidatingmixOnZOrderChangingmouseDownmouseDragmouseEntermouseExitmouseMovemouseUpmovenextFocusnumListeningpaintpaintAllpaintHeavyweightComponentspointRelativeToComponentpostEventpostsOldMouseEventspreferredSizeprepareImageprepareImageprintprintAllprintHeavyweightComponentsprocessComponentEventprocessFocusEventprocessHierarchyBoundsEventprocessHierarchyEventprocessInputMethodEventprocessKeyEventprocessMouseEventprocessMouseMotionEventprocessMouseWheelEventrelocateComponentremoveremoveComponentListenerremoveFocusListenerremoveHierarchyBoundsListenerremoveHierarchyListenerremoveInputMethodListenerremoveKeyListenerremoveMouseListenerremoveMouseMotionListenerremoveMouseWheelListenerremovePropertyChangeListenerremovePropertyChangeListenerrepaintrepaintrepaintrepaintrequestFocusrequestFocusrequestFocusrequestFocusrequestFocusHelperrequestFocusHelperrequestFocusInWindowrequestFocusInWindowrequestFocusInWindowrequestFocusInWindowreshaperesizeresizerevalidaterevalidateSynchronouslysetAutoFocusTransferOnDisposalsetBoundssetBoundssetBoundsOpsetComponentOrientationsetCursorsetDropTargetsetEnabledsetFocusablesetFocusTraversalKeyssetFocusTraversalKeys_NoIDChecksetFocusTraversalKeysEnabledsetFontsetForegroundsetGraphicsConfigurationsetIgnoreRepaintsetLocalesetLocationsetLocationsetMaximumSizesetMinimumSizesetMixingCutoutShapesetNamesetPreferredSizesetRequestFocusControllersetSizesetSizesetVisibleshowshowsizesubtractAndApplyShapesubtractAndApplyShapeBelowMetoStringtransferFocustransferFocustransferFocusBackwardtransferFocusBackwardtransferFocusUpCycleupdateupdateChildGraphicsDataupdateCursorImmediatelyupdateGraphicsDataupdateZOrdervalidate