Google Web Toolkit
Search Google Code:

# Class TextBoxBase

public class TextBoxBase
extends FocusWidget
implements SourcesKeyboardEvents, SourcesChangeEvents, SourcesClickEvents, HasText, HasName
// Superclass of `PasswordTextBox`, `TextArea`, `TextBox`
Abstract base class for all text entry widgets.

## Nested Classes

TextBoxBase.TextAlignConstant | Text alignment constant, used in TextAlignConstant).

## Fields

ALIGN_CENTER | Center the text.
ALIGN_JUSTIFY | Justify the text.
ALIGN_LEFT | Align the text to the left edge.
ALIGN_RIGHT | Align the text to the right.

## Constructors

TextBoxBase(Element) | Creates a text box that wraps the given browser element handle.

## Methods

addChangeListener(ChangeListener) | Adds a listener interface to receive change events.
addClickListener(ClickListener) |
addKeyboardListener(KeyboardListener) |
cancelKey() | If a keyboard event is currently being handled on this text box, calling this method will suppress it.
getCursorPos() | Gets the current position of the cursor (this also serves as the beginning of the text selection).
getImpl() |
getName() | Gets the widget's name.
getSelectedText() | Gets the text currently selected within this text box.
getSelectionLength() | Gets the length of the current text selection.
getText() | Gets this object's text.
isReadOnly() | Determines whether or not the widget is read-only.
onBrowserEvent(Event) |
removeChangeListener(ChangeListener) | Removes a previously added listener interface.
removeClickListener(ClickListener) |
removeKeyboardListener(KeyboardListener) |
selectAll() | Selects all of the text in the box.
setCursorPos(int) | Sets the cursor position.
setKey(char) | If a keyboard event is currently being handled by the text box, this method replaces the unicode character or key code associated with it.
setName(String) | Sets the widget's name.
setReadOnly(boolean) | Turns read-only mode on or off.
setSelectionRange(int, int) | Sets the range of text to be selected.
setText(String) | Sets this object's text.
setTextAlignment(TextBoxBase.TextAlignConstant) | Sets the alignment of the text in the text box.

## Field Detail

### ALIGN_CENTER

public static final TextBoxBase.TextAlignConstant ALIGN_CENTER
Center the text.

### ALIGN_JUSTIFY

public static final TextBoxBase.TextAlignConstant ALIGN_JUSTIFY
Justify the text.

### ALIGN_LEFT

public static final TextBoxBase.TextAlignConstant ALIGN_LEFT
Align the text to the left edge.

### ALIGN_RIGHT

public static final TextBoxBase.TextAlignConstant ALIGN_RIGHT
Align the text to the right.

## Constructor Detail

### TextBoxBase

protected TextBoxBase(Element elem)
Creates a text box that wraps the given browser element handle. This is only used by subclasses.

#### Parameters

elem
  the browser element to wrap

## Method Detail

### addChangeListener

public void addChangeListener(ChangeListener listener)
Adds a listener interface to receive change events.

#### Parameters

listener
  the listener interface to add

### addClickListener

public void addClickListener(ClickListener listener)

#### Parameters

listener

### addKeyboardListener

public void addKeyboardListener(KeyboardListener listener)

#### Parameters

listener

### cancelKey

public void cancelKey()
If a keyboard event is currently being handled on this text box, calling this method will suppress it. This allows listeners to easily filter keyboard input.

### getCursorPos

public int getCursorPos()
Gets the current position of the cursor (this also serves as the beginning of the text selection).

#### Return Value

the cursor's position

### getImpl

protected TextBoxImpl getImpl()

### getName

public String getName()
Gets the widget's name.

#### Return Value

the widget's name

### getSelectedText

public String getSelectedText()
Gets the text currently selected within this text box.

#### Return Value

the selected text, or an empty string if none is selected

### getSelectionLength

public int getSelectionLength()
Gets the length of the current text selection.

#### Return Value

the text selection length

### getText

public String getText()
Gets this object's text.

#### Return Value

the object's text

### isReadOnly

public boolean isReadOnly()
Determines whether or not the widget is read-only.

#### Return Value

`true` if the widget is currently read-only, `false` if the widget is currently editable

### onBrowserEvent

public void onBrowserEvent(Event event)

#### Parameters

event

### removeChangeListener

public void removeChangeListener(ChangeListener listener)
Removes a previously added listener interface.

#### Parameters

listener
  the listener interface to remove

### removeClickListener

public void removeClickListener(ClickListener listener)

#### Parameters

listener

### removeKeyboardListener

public void removeKeyboardListener(KeyboardListener listener)

#### Parameters

listener

### selectAll

public void selectAll()
Selects all of the text in the box.

### setCursorPos

public void setCursorPos(int pos)
Sets the cursor position.

#### Parameters

pos
  the new cursor position

### setKey

public void setKey(char key)
If a keyboard event is currently being handled by the text box, this method replaces the unicode character or key code associated with it. This allows listeners to easily filter keyboard input.

#### Parameters

key
  the new key value

### setName

public void setName(String name)
Sets the widget's name.

#### Parameters

name
  the widget's new name

### setReadOnly

public void setReadOnly(boolean readOnly)
Turns read-only mode on or off.

#### Parameters

readOnly
  if `true`, the widget becomes read-only; if `false` the widget becomes editable

### setSelectionRange

public void setSelectionRange(int pos, int length)
Sets the range of text to be selected.

#### Parameters

pos
  the position of the first character to be selected
length
  the number of characters to be selected

### setText

public void setText(String text)
Sets this object's text.

#### Parameters

text
  the object's new text

### setTextAlignment

public void setTextAlignment(TextBoxBase.TextAlignConstant align)
Sets the alignment of the text in the text box.

#### Parameters

align
  the text alignment (as specified by ALIGN_CENTER, ALIGN_JUSTIFY, ALIGN_LEFT, and ALIGN_RIGHT)