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 TextEvent
s.
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 int getSelectionStart()
public void setSelectionStart(int selectionStart)
public int getSelectionEnd()
public void setSelectionEnd(int selectionEnd)
public void select(int selectionStart, int selectionEnd)
public void selectAll()
public 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()