Home » openjdk-7 » java » awt » [javadoc | source]
java.awt
public class: TextComponent [javadoc | source]
java.lang.Object
   java.awt.Component
      java.awt.TextComponent

All Implemented Interfaces:
    Accessible, MenuContainer, Serializable, ImageObserver

Direct Known Subclasses:
    TextArea, TextField

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.

Nested Class Summary:
protected class  TextComponent.AccessibleAWTTextComponent  This class implements accessibility support for the TextComponent class. It provides an implementation of the Java Accessibility API appropriate to text component user-interface elements. 
Field Summary
 String text    The value of the text. A null value is the same as "". 
 boolean editable    A boolean indicating whether or not this TextComponent is editable. It will be true if the text component is editable and false if not. 
 int selectionStart    The selection refers to the selected text, and the selectionStart is the start position of the selected text. 
 int selectionEnd    The selection refers to the selected text, and the selectionEnd is the end position of the selected text. 
 boolean backgroundSetByClientCode     
protected transient  TextListener textListener     
Fields inherited from java.awt.Component:
peer,  parent,  appContext,  x,  y,  width,  height,  foreground,  background,  font,  peerFont,  cursor,  locale,  bufferStrategy,  ignoreRepaint,  visible,  enabled,  dropTarget,  popups,  focusTraversalKeys,  LOCK,  minSize,  minSizeSet,  prefSize,  prefSizeSet,  maxSize,  maxSizeSet,  componentOrientation,  newEventsOnly,  componentListener,  focusListener,  hierarchyListener,  hierarchyBoundsListener,  keyListener,  mouseListener,  mouseMotionListener,  mouseWheelListener,  inputMethodListener,  windowClosingException,  actionListenerK,  adjustmentListenerK,  componentListenerK,  containerListenerK,  focusListenerK,  itemListenerK,  keyListenerK,  mouseListenerK,  mouseMotionListenerK,  mouseWheelListenerK,  textListenerK,  ownedWindowK,  windowListenerK,  inputMethodListenerK,  hierarchyListenerK,  hierarchyBoundsListenerK,  windowStateListenerK,  windowFocusListenerK,  eventMask,  isInc,  incRate,  TOP_ALIGNMENT,  CENTER_ALIGNMENT,  BOTTOM_ALIGNMENT,  LEFT_ALIGNMENT,  RIGHT_ALIGNMENT,  isPacked,  backgroundEraseDisabled,  eventCache,  accessibleContext
Constructor:
 TextComponent(String text) throws HeadlessException 
    Constructs a new text component initialized with the specified text. Sets the value of the cursor to Cursor.TEXT_CURSOR.
    Parameters:
    text - the text to be displayed; if text is null, the empty string "" will be displayed
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless returns true
    Also see:
    java.awt.GraphicsEnvironment#isHeadless
    java.awt.Cursor
    exception: HeadlessException - if GraphicsEnvironment.isHeadless returns true
Method from java.awt.TextComponent Summary:
addNotify,   addTextListener,   areInputMethodsEnabled,   enableInputMethods,   eventEnabled,   getAccessibleContext,   getBackground,   getCaretPosition,   getCharacterBounds,   getIndexAtPoint,   getInputMethodRequests,   getListeners,   getSelectedText,   getSelectionEnd,   getSelectionStart,   getText,   getTextListeners,   isEditable,   paramString,   processEvent,   processTextEvent,   removeNotify,   removeTextListener,   select,   selectAll,   setBackground,   setCaretPosition,   setEditable,   setSelectionEnd,   setSelectionStart,   setText
Methods from java.awt.Component:
action,   add,   addComponentListener,   addFocusListener,   addHierarchyBoundsListener,   addHierarchyListener,   addInputMethodListener,   addKeyListener,   addMouseListener,   addMouseMotionListener,   addMouseWheelListener,   addNotify,   addPropertyChangeListener,   addPropertyChangeListener,   adjustListeningChildrenOnParent,   applyComponentOrientation,   applyCompoundShape,   applyCurrentShape,   areBoundsValid,   areFocusTraversalKeysSet,   areInputMethodsEnabled,   autoProcessMouseWheel,   bounds,   canBeFocusOwner,   canBeFocusOwnerRecursively,   checkGD,   checkImage,   checkImage,   checkTreeLock,   checkWindowClosingException,   clearCurrentFocusCycleRootOnHide,   clearMostRecentFocusOwnerOnHide,   coalesceEvents,   constructComponentName,   contains,   contains,   containsFocus,   countHierarchyMembers,   createBufferStrategy,   createBufferStrategy,   createHierarchyEvents,   createImage,   createImage,   createVolatileImage,   createVolatileImage,   deliverEvent,   disable,   disableEvents,   dispatchEvent,   dispatchEventImpl,   dispatchMouseWheelToAncestor,   doLayout,   enable,   enable,   enableEvents,   enableInputMethods,   eventEnabled,   eventTypeEnabled,   findUnderMouseInWindow,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   firePropertyChange,   getAccessControlContext,   getAccessibleContext,   getAccessibleIndexInParent,   getAccessibleStateSet,   getAlignmentX,   getAlignmentY,   getBackBuffer,   getBackground,   getBaseline,   getBaselineResizeBehavior,   getBounds,   getBounds,   getBoundsOp,   getBufferStrategy,   getColorModel,   getComponentAt,   getComponentAt,   getComponentListeners,   getComponentOrientation,   getContainer,   getContainingWindow,   getCursor,   getCursor_NoClientCode,   getDropTarget,   getFocusCycleRootAncestor,   getFocusListeners,   getFocusTraversalKeys,   getFocusTraversalKeysEnabled,   getFocusTraversalKeys_NoIDCheck,   getFont,   getFontMetrics,   getFont_NoClientCode,   getForeground,   getGraphics,   getGraphicsConfiguration,   getGraphicsConfiguration_NoClientCode,   getGraphics_NoClientCode,   getHWPeerAboveMe,   getHeight,   getHierarchyBoundsListeners,   getHierarchyListeners,   getIgnoreRepaint,   getInputContext,   getInputMethodListeners,   getInputMethodRequests,   getKeyListeners,   getListeners,   getLocale,   getLocation,   getLocation,   getLocationOnScreen,   getLocationOnScreen_NoTreeLock,   getLocationOnWindow,   getMaximumSize,   getMinimumSize,   getMouseListeners,   getMouseMotionListeners,   getMousePosition,   getMouseWheelListeners,   getName,   getNativeContainer,   getNextFocusCandidate,   getNormalShape,   getObjectLock,   getOpaqueShape,   getParent,   getParent_NoClientCode,   getPeer,   getPreferredSize,   getPropertyChangeListeners,   getPropertyChangeListeners,   getSiblingIndexAbove,   getSiblingIndexBelow,   getSize,   getSize,   getToolkit,   getToolkitImpl,   getTraversalRoot,   getTreeLock,   getWidth,   getX,   getY,   gotFocus,   handleEvent,   hasFocus,   hide,   imageUpdate,   initializeFocusTraversalKeys,   inside,   invalidate,   invalidateIfValid,   invalidateParent,   isAutoFocusTransferOnDisposal,   isBackgroundSet,   isCoalescingEnabled,   isCursorSet,   isDisplayable,   isDoubleBuffered,   isEnabled,   isEnabledImpl,   isFocusCycleRoot,   isFocusOwner,   isFocusTraversable,   isFocusTraversableOverridden,   isFocusable,   isFontSet,   isForegroundSet,   isInstanceOf,   isLightweight,   isMaximumSizeSet,   isMinimumSizeSet,   isMixingNeeded,   isNonOpaqueForMixing,   isOpaque,   isPreferredSizeSet,   isRecursivelyVisible,   isSameOrAncestorOf,   isShowing,   isValid,   isVisible,   isVisible_NoClientCode,   keyDown,   keyUp,   layout,   lightweightPaint,   lightweightPrint,   list,   list,   list,   list,   list,   locate,   location,   lostFocus,   minimumSize,   mixOnHiding,   mixOnReshaping,   mixOnShowing,   mixOnValidating,   mixOnZOrderChanging,   mouseDown,   mouseDrag,   mouseEnter,   mouseExit,   mouseMove,   mouseUp,   move,   nextFocus,   numListening,   paint,   paintAll,   paintHeavyweightComponents,   paramString,   pointRelativeToComponent,   postEvent,   postsOldMouseEvents,   preferredSize,   prepareImage,   prepareImage,   print,   printAll,   printHeavyweightComponents,   processComponentEvent,   processEvent,   processFocusEvent,   processHierarchyBoundsEvent,   processHierarchyEvent,   processInputMethodEvent,   processKeyEvent,   processMouseEvent,   processMouseMotionEvent,   processMouseWheelEvent,   relocateComponent,   remove,   removeComponentListener,   removeFocusListener,   removeHierarchyBoundsListener,   removeHierarchyListener,   removeInputMethodListener,   removeKeyListener,   removeMouseListener,   removeMouseMotionListener,   removeMouseWheelListener,   removeNotify,   removePropertyChangeListener,   removePropertyChangeListener,   repaint,   repaint,   repaint,   repaint,   requestFocus,   requestFocus,   requestFocus,   requestFocus,   requestFocusHelper,   requestFocusHelper,   requestFocusInWindow,   requestFocusInWindow,   requestFocusInWindow,   requestFocusInWindow,   reshape,   resize,   resize,   revalidate,   setAutoFocusTransferOnDisposal,   setBackground,   setBounds,   setBounds,   setBoundsOp,   setComponentOrientation,   setCursor,   setDropTarget,   setEnabled,   setFocusTraversalKeys,   setFocusTraversalKeysEnabled,   setFocusTraversalKeys_NoIDCheck,   setFocusable,   setFont,   setForeground,   setGraphicsConfiguration,   setIgnoreRepaint,   setLocale,   setLocation,   setLocation,   setMaximumSize,   setMinimumSize,   setName,   setPreferredSize,   setRequestFocusController,   setSize,   setSize,   setVisible,   show,   show,   size,   subtractAndApplyShape,   subtractAndApplyShapeBelowMe,   toString,   transferFocus,   transferFocus,   transferFocusBackward,   transferFocusBackward,   transferFocusUpCycle,   update,   updateCursorImmediately,   updateGraphicsData,   updateZOrder,   validate
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.awt.TextComponent Detail:
 public  void addNotify() 
    Makes this Component displayable by connecting it to a native screen resource. This method is called internally by the toolkit and should not be called directly by programs.
 public synchronized  void addTextListener(TextListener l) 
    Adds the specified text event listener to receive text events from this text component. If l is null, no exception is thrown and no action is performed.

    Refer to AWT Threading Issues for details on AWT's threading model.

 boolean areInputMethodsEnabled() 
 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.
 boolean eventEnabled(AWTEvent e) 
 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.
 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.
 public synchronized 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.
 Rectangle getCharacterBounds(int i) 
 int getIndexAtPoint(Point p) 
 public InputMethodRequests getInputMethodRequests() 
 public T[] getListeners(Class<T> listenerType) 
    Returns an array of all the objects currently registered as FooListeners upon this TextComponent. FooListeners 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.
 public synchronized String getSelectedText() 
    Returns the selected text from the text that is presented by this text component.
 public synchronized int getSelectionEnd() 
    Gets the end position of the selected text in this text component.
 public synchronized int getSelectionStart() 
    Gets the start position of the selected text in this text component.
 public synchronized String getText() 
    Returns the text that is presented by this text component. By default, this is an empty string.
 public synchronized TextListener[] getTextListeners() 
    Returns an array of all the text listeners registered on this text component.
 public boolean isEditable() 
    Indicates whether or not this text component is editable.
 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.
 protected  void processEvent(AWTEvent e) 
    Processes events on this text component. If the event is a 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.

 protected  void processTextEvent(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 TextListener object is registered via addTextListener
    • Text events are enabled via enableEvents

    Note that if the event parameter is null the behavior is unspecified and may result in an exception.

 public  void removeNotify() 
    Removes the TextComponent's peer. The peer allows us to modify the appearance of the TextComponent without changing its functionality.
 public synchronized  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.

    Refer to AWT Threading Issues for details on AWT's threading model.

 public synchronized  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 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.

 public synchronized  void selectAll() 
    Selects all the text in this text component.
 public  void setBackground(Color c) 
    Sets the background color of this text component.
 public synchronized  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.
 public synchronized  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. By default, non-editable text components have a background color of SystemColor.control. This default can be overridden by calling setBackground.

 public synchronized  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.
 public synchronized  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.
 public synchronized  void setText(String t) 
    Sets the text that is presented by this text component to be the specified text.