Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class java.awt.TextComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.TextComponent
Subclasses:
TextField

public class TextComponent
extends Component
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.

Since:
JDK1.0
Version:
1.40, 06/09/98
See Also:
Serialized Form

Inner classes inherited from class java.awt.Component
Component.NativeInLightFixer
 
Field Summary
boolean editable
          A boolean indicating whether or not this TextComponent is editable.
int selectionEnd
          The selection end.
int selectionStart
          The selection start.
static long serialVersionUID
           
int textComponentSerializedDataVersion
           
java.awt.event.TextListener textListener
           
String text
          The value of the text.
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, assert, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, hasFocus, height, incRate, inputMethodListener, inputMethodListenerK, isInc, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, parent, peer, popups, prefSize, RIGHT_ALIGNMENT, serialVersionUID, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowListenerK, x, y
 
Constructor Summary
TextComponent(String text)
          Constructs a new text component initialized with the specified text.
 
Method Summary
void addTextListener(java.awt.event.TextListener l)
          Adds the specified text event listener to recieve text events from this textcomponent.
boolean areInputMethodsEnabled()
           
void enableInputMethodsIfNecessary()
           
boolean eventEnabled(AWTEvent e)
           
int getCaretPosition()
          Gets the position of the text insertion caret for this text component.
String getSelectedText()
          Gets 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()
          Gets the text that is presented by this text component.
boolean isEditable()
          Indicates whether or not this text component is editable.
String paramString()
          Returns the parameter string representing the state of this text component.
void processEvent(AWTEvent e)
          Processes events on this textcomponent.
void processTextEvent(java.awt.event.TextEvent e)
          Processes text events occurring on this text component by dispatching them to any registered TextListener objects.
void readObject(java.io.ObjectInputStream s)
           
void removeNotify()
          Removes the TextComponent's peer.
void removeTextListener(java.awt.event.TextListener l)
          Removes the specified text event listener so that it no longer receives text events from this textcomponent
void selectAll()
          Selects all the text in this text component.
void select(int selectionStart, int selectionEnd)
          Selects the text between the specified start and end positions.
void setCaretPosition(int position)
          Sets the position of the text insertion caret for this text component.
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.
void writeObject(java.io.ObjectOutputStream s)
           
 
Methods inherited from class java.awt.Component
, action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, coalesceEvents, constructComponentName, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, ensureWindowActivation, eventEnabled, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getNativeContainer, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initIDs, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paint, paramString, postEvent, postsOldMouseEvents, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, readObject, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate, writeObject
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notifyAll, notify, registerNatives, toString, wait, wait, wait
 

Field Detail

text

String text
The value of the text.

editable

boolean editable
A boolean indicating whether or not this TextComponent is editable.

selectionStart

int selectionStart
The selection start.

selectionEnd

int selectionEnd
The selection end.

textListener

protected transient java.awt.event.TextListener textListener

serialVersionUID

private static final long serialVersionUID

textComponentSerializedDataVersion

private int textComponentSerializedDataVersion
Constructor Detail

TextComponent

TextComponent(String text)
Constructs a new text component initialized with the specified text. Sets the value of the cursor to Cursor.TEXT_CURSOR.
Parameters:
text - the initial text that the component presents.
See Also:
java.awt.Cursor
Method Detail

enableInputMethodsIfNecessary

private void enableInputMethodsIfNecessary()

areInputMethodsEnabled

boolean areInputMethodsEnabled()
Overrides:
areInputMethodsEnabled in class Component

removeNotify

public void removeNotify()
Removes the TextComponent's peer. The peer allows us to modify the appearance of the TextComponent without changing its functionality.
Overrides:
removeNotify in class Component

setText

public void setText(String t)
Sets the text that is presented by this text component to be the specified text.
Parameters:
t - the new text.
See Also:
getText

getText

public String getText()
Gets the text that is presented by this text component.
See Also:
setText

getSelectedText

public String getSelectedText()
Gets the selected text from the text that is presented by this text component.
Returns:
the selected text of this text component.
See Also:
select

isEditable

public boolean isEditable()
Indicates whether or not this text component is editable.
Returns:
true if this text component is editable; false otherwise.
See Also:
setEditable

setEditable

public void setEditable(boolean b)
Sets the flag that determines whether or not this text component is editable.

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.

Parameters:
t - a flag indicating whether this text component should be user editable.
See Also:
isEditable


getSelectionStart

public int getSelectionStart()
Gets the start position of the selected text in this text component.
Returns:
the start position of the selected text.
See Also:
setSelectionStart, getSelectionEnd

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.
See Also:
getSelectionStart, setSelectionEnd

getSelectionEnd

public int getSelectionEnd()
Gets the end position of the selected text in this text component.
Returns:
the end position of the selected text.
See Also:
setSelectionEnd, getSelectionStart

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.
See Also:
getSelectionEnd, setSelectionStart

select

public void select(int selectionStart,
                   int selectionEnd)
Selects the text between the specified start and end positions.

This method sets the start and end positions of the selected text, enforcing the restriction that the end position must be greater than or equal to the start position. The start position must be greater than zero, and the end position must be less that or equal to the length of the text component's text. If the caller supplies values that are inconsistent or out of bounds, the method enforces these constraints silently, and without failure.

Parameters:
selectionStart - the start position of the text to select.
selectionEnd - the end position of the text to select.
See Also:
setSelectionStart, setSelectionEnd, selectAll


selectAll

public void selectAll()
Selects all the text in this text component.
See Also:
java.awt.TextComponent@select

setCaretPosition

public void setCaretPosition(int position)
Sets the position of the text insertion caret for this text component.
Parameters:
position - the position of the text insertion caret.
Throws:
java.lang.IllegalArgumentException - if the value supplied for position is less than zero.

getCaretPosition

public int getCaretPosition()
Gets the position of the text insertion caret for this text component.
Returns:
the position of the text insertion caret.

addTextListener

public void addTextListener(java.awt.event.TextListener l)
Adds the specified text event listener to recieve text events from this textcomponent.
Parameters:
l - the text event listener

removeTextListener

public void removeTextListener(java.awt.event.TextListener l)
Removes the specified text event listener so that it no longer receives text events from this textcomponent

eventEnabled

boolean eventEnabled(AWTEvent e)
Overrides:
eventEnabled in class Component

processEvent

protected void processEvent(AWTEvent e)
Processes events on this textcomponent. If the event is a TextEvent, it invokes the processTextEvent method, else it invokes its superclass's processEvent.
Parameters:
e - the event
Overrides:
processEvent in class Component

processTextEvent

protected void processTextEvent(java.awt.event.TextEvent e)
Processes text events occurring on this text component by dispatching them to any registered 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: a) A TextListener object is registered via addTextListener() b) Text events are enabled via enableEvents()
Parameters:
e - the text event
See Also:
enableEvents

paramString

protected String paramString()
Returns the parameter string representing the state of this text component. This string is useful for debugging.
Returns:
the parameter string of this text component.
Overrides:
paramString in class Component

writeObject

private void writeObject(java.io.ObjectOutputStream s)
                 throws java.io.IOException
Overrides:
writeObject in class Component

readObject

private void readObject(java.io.ObjectInputStream s)
                throws java.lang.ClassNotFoundException,
                       java.io.IOException
Overrides:
readObject in class Component

Class | Tree | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD