public class TextComponent extends Component implements Serializable, Accessible
Modifier and Type | Class and Description |
---|---|
protected class |
TextComponent.AccessibleAWTTextComponent |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected TextListener |
textListener
A list of listeners that will receive events from this object.
|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Modifier and Type | Method and Description |
---|---|
void |
addTextListener(TextListener listener)
Adds a new listener to the list of text listeners for this
component.
|
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this
TextComponent . |
int |
getCaretPosition()
Returns the current caret position in the text.
|
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as FooListeners
upon this
TextComponent . |
String |
getSelectedText()
Returns a string that contains the text that is currently selected.
|
int |
getSelectionEnd()
Returns the ending position of the selected text region.
|
int |
getSelectionStart()
Returns the starting position of the selected text region.
|
String |
getText()
Returns the text in this component
|
TextListener[] |
getTextListeners()
Returns all text listeners registered to this object.
|
boolean |
isEditable()
Tests whether or not this component's text can be edited.
|
protected String |
paramString()
Returns a debugging string.
|
protected void |
processEvent(AWTEvent event)
Processes the specified event for this component.
|
protected void |
processTextEvent(TextEvent event)
Processes the specified text event by dispatching it to any listeners
that are registered.
|
void |
removeNotify()
Notifies the component that it should destroy its native peer.
|
void |
removeTextListener(TextListener listener)
Removes the specified listener from the list of listeners
for this component.
|
void |
select(int selectionStart,
int selectionEnd)
This method sets the selected text range to the text between the
specified start and end positions.
|
void |
selectAll()
Selects all of the text in the component.
|
void |
setCaretPosition(int caretPosition)
Sets the caret position to the specified value.
|
void |
setEditable(boolean editable)
Sets whether or not this component's text can be edited.
|
void |
setSelectionEnd(int selectionEnd)
Sets the ending position of the selected region to the
specified value.
|
void |
setSelectionStart(int selectionStart)
Sets the starting position of the selected region to the
specified value.
|
void |
setText(String text)
Sets the text in this component to the specified string.
|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, 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, setBackground, 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
protected transient TextListener textListener
public String getText()
public void setText(String text)
text
- The new text for this component.public String getSelectedText()
public int getSelectionStart()
public void setSelectionStart(int selectionStart)
selectionStart
- The new start position for selected text.public int getSelectionEnd()
public void setSelectionEnd(int selectionEnd)
selectionEnd
- The new start position for selected text.public void select(int selectionStart, int selectionEnd)
selectionStart
- The new start position for the selected text.selectionEnd
- The new end position for the selected text.public void selectAll()
public int getCaretPosition()
public void setCaretPosition(int caretPosition)
caretPosition
- The new caret position.IllegalArgumentException
- If the value supplied for position
is less than zero.public boolean isEditable()
true
if the text can be edited, false
otherwise.public void setEditable(boolean editable)
editable
- true
to enable editing of the text,
false
to disable it.public void removeNotify()
removeNotify
in class Component
Component.isDisplayable()
,
Component.addNotify()
public void addTextListener(TextListener listener)
listener
- The listener to be added.public void removeTextListener(TextListener listener)
listener
- The listener to remove.protected void processEvent(AWTEvent event)
processTextEvent()
method.
All other events are passed to the superclass method.processEvent
in class Component
event
- The event to process.Component.processComponentEvent(ComponentEvent)
,
Component.processFocusEvent(FocusEvent)
,
Component.processKeyEvent(KeyEvent)
,
Component.processMouseEvent(MouseEvent)
,
Component.processMouseMotionEvent(MouseEvent)
,
Component.processInputMethodEvent(InputMethodEvent)
,
Component.processHierarchyEvent(HierarchyEvent)
,
Component.processMouseWheelEvent(MouseWheelEvent)
protected void processTextEvent(TextEvent event)
enableEvents()
.event
- The text event to process.protected String paramString()
paramString
in class Component
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
TextComponent
. FooListeners are registered using
the addFooListener method.getListeners
in class Component
listenerType
- the class of listeners to filter (null
not permitted).ClassCastException
- If listenerType doesn't specify a class or
interface that implements java.util.EventListener.Component.getComponentListeners()
,
Component.getFocusListeners()
,
Component.getHierarchyListeners()
,
Component.getHierarchyBoundsListeners()
,
Component.getKeyListeners()
,
Component.getMouseListeners()
,
Component.getMouseMotionListeners()
,
Component.getMouseWheelListeners()
,
Component.getInputMethodListeners()
,
Component.getPropertyChangeListeners()
public TextListener[] getTextListeners()
public AccessibleContext getAccessibleContext()
TextComponent
.
The context is created, if necessary.getAccessibleContext
in interface Accessible
getAccessibleContext
in class Component