TextComponent

Both TextArea and TextField are subclasses of java.awt.TextComponent. This class contains methods common to both classes including several you've already seen: getText(), setText(), and setEditable(). The TextComponent class also defines methods for manipulating the selection and the caret and for processing TextEvents.

The selection is used for copy and paste and other purposes. The first character in a TextComponent is character 0; the second is character 1, and so on.

  public synchronized int getSelectionStart()
  public synchronized void setSelectionStart(int selectionStart)
  public synchronized int getSelectionEnd()
  public synchronized void setSelectionEnd(int selectionEnd)
  public synchronized void select(int selectionStart, int selectionEnd)
  public synchronized void selectAll()
  public synchronized String getSelectedText()
The caret is the insertion point. It's where text appears when the user types. There are two methods to adjust it:

  public void setCaretPosition(int position)
  public int getCaretPosition()

Previous | Next | Top
Last Modified November 15, 1999
Copyright 1997, 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu