java.lang.Object java.awt.Component java.awt.TextComponent
public class TextComponent
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.
void
addNotify()
void
addTextListener(TextListener l)
void
enableInputMethods(boolean enable)
AccessibleContext
getAccessibleContext()
Color
getBackground()
int
getCaretPosition()
InputMethodRequests
getInputMethodRequests()
<T extends EventListener>
T[]
getListeners(Class<T> listenerType)
FooListener
s upon this TextComponent
. String
getSelectedText()
int
getSelectionEnd()
int
getSelectionStart()
String
getText()
TextListener[]
getTextListeners()
boolean
isEditable()
protected String
paramString()
TextComponent
. protected void
processEvent(AWTEvent e)
protected void
processTextEvent(TextEvent e)
TextListener
objects. void
removeNotify()
TextComponent
's peer. void
removeTextListener(TextListener l)
l
is null
, no exception is thrown and no action is performed. void
select(int selectionStart, int selectionEnd)
void
selectAll()
void
setBackground(Color c)
void
setCaretPosition(int position)
void
setEditable(boolean b)
void
setSelectionEnd(int selectionEnd)
void
setSelectionStart(int selectionStart)
void
setText(String t)
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, 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, 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
textListener
protected transient TextListener textListener
public void enableInputMethods(boolean enable)
Component
enableInputMethods
in class Component
enable
- true to enable, false to disable
Component.processKeyEvent(java.awt.event.KeyEvent)
public InputMethodRequests getInputMethodRequests()
Component
InputMethodRequests
instance. At the same time, it also has to handle input method events.
getInputMethodRequests
in class Component
null
by default
Component.addInputMethodListener(java.awt.event.InputMethodListener)
public void addNotify()
addNotify
in class Component
removeNotify()
public void removeNotify()
TextComponent
's peer. The peer allows us to modify the appearance of the TextComponent
without changing its functionality.
removeNotify
in class Component
Component.isDisplayable()
, Component.addNotify()
public void setText(String t)
t
- the new text; if this parameter is null
then the text is set to the empty string ""
getText()
public String getText()
TextComponent
setText(java.lang.String)
public String getSelectedText()
select(int, int)
public boolean isEditable()
true
if this text component is editable; false
otherwise.
setEditable(boolean)
public void setEditable(boolean b)
If the flag is set to true
, this text component becomes user editable. If the flag is set to false
, the user cannot change the text 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.
b
- a flag indicating whether this text component is user editable.
isEditable()
public Color getBackground()
getBackground
in class Component
setBackground(Color)
public void setBackground(Color c)
setBackground
in class Component
c
- 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.
getBackground()
public int getSelectionStart()
setSelectionStart(int)
, getSelectionEnd()
public void setSelectionStart(int selectionStart)
selectionStart
that is out of bounds, the method enforces these constraints silently, and without failure.
selectionStart
- the start position of the selected text
getSelectionStart()
, setSelectionEnd(int)
public int getSelectionEnd()
setSelectionEnd(int)
, getSelectionStart()
public void setSelectionEnd(int selectionEnd)
selectionEnd
that is out of bounds, the method enforces these constraints silently, and without failure.
selectionEnd
- the end position of the selected text
getSelectionEnd()
, setSelectionStart(int)
public void select(int selectionStart, int selectionEnd)
This method sets the start and end positions of the selected text, enforcing the restriction that the start position must be greater than or equal to zero. The end position must be greater than or equal to the start position, and less than or equal to the length of the text component's text. The character positions are indexed starting with zero. The length of the selection is endPosition
- startPosition
, so the character at endPosition
is not selected. If the start and end positions of the selected text are equal, all text is deselected.
If the caller supplies values that are inconsistent or out of bounds, the method enforces these constraints silently, and without failure. Specifically, if the start position or end position is greater than the length of the text, it is reset to equal the text length. If the start position is less than zero, it is reset to zero, and if the end position is less than the start position, it is reset to the start position.
selectionStart
- the zero-based index of the first character (char
value) to be selected
selectionEnd
- the zero-based end position of the text to be selected; the character (char
value) at selectionEnd
is not selected
setSelectionStart(int)
, setSelectionEnd(int)
, selectAll()
public void selectAll()
select(int, int)
public void setCaretPosition(int position)
TextComponent
contains no text) and no error is returned. If the passed-in value is less than 0, an IllegalArgumentException
is thrown.
position
- the position of the text insertion caret
IllegalArgumentException
- if position
is less than zero
public int getCaretPosition()
setCaretPosition(int)
public void addTextListener(TextListener l)
l
is null
, no exception is thrown and no action is performed.
l
- the text event listener
removeTextListener(java.awt.event.TextListener)
, getTextListeners()
, TextListener
public void removeTextListener(TextListener l)
l
is null
, no exception is thrown and no action is performed.
l
- the text listener
addTextListener(java.awt.event.TextListener)
, getTextListeners()
, TextListener
public TextListener[] getTextListeners()
TextListener
s or an empty array if no text listeners are currently registered
addTextListener(java.awt.event.TextListener)
, removeTextListener(java.awt.event.TextListener)
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListener
s upon this TextComponent
. FooListener
s are registered using the addFooListener
method.
You can specify the listenerType
argument with a class literal, such as FooListener.class
. For example, you can query a TextComponent
t
for its text listeners with the following code:
TextListener[] tls = (TextListener[])(t.getListeners(TextListener.class));If no such listeners exist, this method returns an empty array.
getListeners
in class Component
listenerType
- the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
FooListener
s on this text component, or an empty array if no such listeners have been added
ClassCastException
- if listenerType
doesn't specify a class or interface that implements java.util.EventListener
getTextListeners()
protected void processEvent(AWTEvent e)
TextEvent
, it invokes the processTextEvent
method else it invokes its superclass's processEvent
.
Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
processEvent
in class Component
e
- the event
Component.processComponentEvent(java.awt.event.ComponentEvent)
, Component.processFocusEvent(java.awt.event.FocusEvent)
, Component.processKeyEvent(java.awt.event.KeyEvent)
, Component.processMouseEvent(java.awt.event.MouseEvent)
, Component.processMouseMotionEvent(java.awt.event.MouseEvent)
, Component.processInputMethodEvent(java.awt.event.InputMethodEvent)
, Component.processHierarchyEvent(java.awt.event.HierarchyEvent)
, Component.processMouseWheelEvent(java.awt.event.MouseWheelEvent)
protected void processTextEvent(TextEvent e)
TextListener
objects.
NOTE: This method will not be called unless text events are enabled for this component. This happens when one of the following occurs:
TextListener
object is registered via addTextListener
enableEvents
Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
e
- the text event
Component.enableEvents(long)
protected String paramString()
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
.
paramString
in class Component
public AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
getAccessibleContext
in class Component
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4