GeezerVison is showing docs.oracle.com — TextComponent (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
java.awt
Class TextComponent
-
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
void |
addNotify() |
Makes this Component displayable by connecting it to a
native screen resource.
|
void |
addTextListener(TextListener l) |
Adds the specified text event listener to receive text events
from this text component.
|
void |
enableInputMethods(boolean enable) |
Enables or disables input method support for this text component.
|
AccessibleContext |
getAccessibleContext() |
Gets the AccessibleContext associated with this TextComponent.
|
Color |
getBackground() |
Gets the background color of this text component.
|
int |
getCaretPosition() |
Returns the position of the text insertion caret.
|
InputMethodRequests |
getInputMethodRequests() |
Gets the input method request handler which supports
requests from input methods for this component.
|
<T extends EventListener> T[] |
getListeners(Class<T> listenerType) |
Returns an array of all the objects currently registered
as FooListeners
upon this TextComponent.
|
String |
getSelectedText() |
Returns the selected text from the text that is
presented by this text component.
|
int |
getSelectionEnd() |
Gets the end position of the selected text in
this text component.
|
int |
getSelectionStart() |
Gets the start position of the selected text in
this text component.
|
String |
getText() |
Returns the text that is presented by this text component.
|
TextListener[] |
getTextListeners() |
Returns an array of all the text listeners
registered on this text component.
|
boolean |
isEditable() |
Indicates whether or not this text component is editable.
|
protected String |
paramString() |
Returns a string representing the state of this
TextComponent.
|
protected void |
processEvent(AWTEvent e) |
Processes events on this text component.
|
protected void |
processTextEvent(TextEvent e) |
Processes text events occurring on this text component by
dispatching them to any registered TextListener objects.
|
void |
removeNotify() |
Removes the TextComponent's peer.
|
void |
removeTextListener(TextListener 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.
|
void |
select(int selectionStart,
int selectionEnd) |
Selects the text between the specified start and end positions.
|
void |
selectAll() |
Selects all the text in this text component.
|
void |
setBackground(Color c) |
Sets the background color of this text component.
|
void |
setCaretPosition(int position) |
Sets the position of the text insertion caret.
|
void |
setEditable(boolean b) |
Sets the flag that determines whether or not this
text component is editable.
|
void |
setSelectionEnd(int selectionEnd) |
Sets the selection end for this text component to
the specified position.
|
void |
setSelectionStart(int selectionStart) |
Sets the selection start for this text component to
the specified position.
|
void |
setText(String t) |
Sets the text that is presented by this
text component to be the specified text.
|
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
Method Detail
-
enableInputMethods
public void enableInputMethods(boolean enable)
Enables or disables input method support for this text component. If input
method support is enabled and the text component also processes key events,
incoming events are offered to the current input method and will only be
processed by the component or dispatched to its listeners if the input method
does not consume them. Whether and how input method support for this text
component is enabled or disabled by default is implementation dependent.
- Overrides:
enableInputMethods in class Component
- Parameters:
enable - true to enable, false to disable
- Since:
- 1.2
- See Also:
Component.processKeyEvent(java.awt.event.KeyEvent)
-
getBackground
public Color getBackground()
Gets the background color 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.
- Overrides:
getBackground in class Component
- 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.
- Since:
- JDK1.0
- See Also:
setBackground(Color)
-
setSelectionStart
public 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 for selectionStart
that 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:
getSelectionStart(),
setSelectionEnd(int)
-
setSelectionEnd
public 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 for selectionEnd
that 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:
getSelectionEnd(),
setSelectionStart(int)
-
setCaretPosition
public 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
the TextComponent contains no text)
and no error is returned. If the passed-in value is
less than 0, an IllegalArgumentException
is thrown.
- Parameters:
position - the position of the text insertion caret
- Throws:
IllegalArgumentException - if position
is less than zero
- Since:
- JDK1.1
-
getCaretPosition
public 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:
setCaretPosition(int)
-
paramString
protected String paramString()
Returns a string representing the state of this
TextComponent. This
method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null.
- Overrides:
paramString in class Component
- Returns:
- the parameter string of this text component
-
getAccessibleContext
public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this TextComponent.
For text components, the AccessibleContext takes the form of an
AccessibleAWTTextComponent.
A new AccessibleAWTTextComponent instance is created if necessary.
- Specified by:
getAccessibleContext in interface Accessible
- Overrides:
getAccessibleContext in class Component
- Returns:
- an AccessibleAWTTextComponent that serves as the
AccessibleContext of this TextComponent
- Since:
- 1.3
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|