Google Web Toolkit
Search Google Code:

# Class FocusWidget

public class FocusWidget
extends Widget
implements SourcesClickEvents, SourcesFocusEvents, HasFocus
// Superclass of `ButtonBase`, `ListBox`, `RichTextArea`, `TextBoxBase`
Abstract base class for most widgets that can receive keyboard focus.

## Constructors

FocusWidget() | Creates a new focus widget with no element.
FocusWidget(Element) | Creates a new focus widget that wraps the specified browser element.

## Methods

addClickListener(ClickListener) | Adds a listener interface to receive click events.
addFocusListener(FocusListener) | Adds a listener interface to receive mouse events.
addKeyboardListener(KeyboardListener) | Adds a listener interface to receive keyboard events.
getFocusImpl() | Gets the FocusImpl instance.
getTabIndex() | Gets the widget's position in the tab index.
isEnabled() | Gets whether this widget is enabled.
onBrowserEvent(Event) |
removeClickListener(ClickListener) | Removes a previously added listener interface.
removeFocusListener(FocusListener) | Removes a previously added listener interface.
removeKeyboardListener(KeyboardListener) | Removes a previously added listener interface.
setAccessKey(char) | Sets the widget's 'access key'.
setElement(Element) | Sets this object's browser element.
setEnabled(boolean) | Sets whether this widget is enabled.
setFocus(boolean) | Explicitly focus/unfocus this widget.
setTabIndex(int) | Sets the widget's position in the tab index.

## Constructor Detail

### FocusWidget

protected FocusWidget()
Creates a new focus widget with no element. setElement(Element) must be called before any other methods.

### FocusWidget

protected FocusWidget(Element elem)
Creates a new focus widget that wraps the specified browser element.

#### Parameters

elem
  the element to be wrapped

## Method Detail

### addClickListener

public void addClickListener(ClickListener listener)
Adds a listener interface to receive click events.

#### Parameters

listener
  the listener interface to add

### addFocusListener

public void addFocusListener(FocusListener listener)
Adds a listener interface to receive mouse events.

#### Parameters

listener
  the listener interface to add

### addKeyboardListener

public void addKeyboardListener(KeyboardListener listener)
Adds a listener interface to receive keyboard events.

#### Parameters

listener
  the listener interface to add

### getFocusImpl

protected static FocusImpl getFocusImpl()
Gets the FocusImpl instance.

#### Return Value

impl

### getTabIndex

public int getTabIndex()
Gets the widget's position in the tab index.

#### Return Value

the widget's tab index

### isEnabled

public boolean isEnabled()
Gets whether this widget is enabled.

#### Return Value

`true` if the widget is enabled

### onBrowserEvent

public void onBrowserEvent(Event event)

#### Parameters

event

### removeClickListener

public void removeClickListener(ClickListener listener)
Removes a previously added listener interface.

#### Parameters

listener
  the listener interface to remove

### removeFocusListener

public void removeFocusListener(FocusListener listener)
Removes a previously added listener interface.

#### Parameters

listener
  the listener interface to remove

### removeKeyboardListener

public void removeKeyboardListener(KeyboardListener listener)
Removes a previously added listener interface.

#### Parameters

listener
  the listener interface to remove

### setAccessKey

public void setAccessKey(char key)
Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.

#### Parameters

key
  the widget's access key

### setElement

protected void setElement(Element elem)
Sets this object's browser element. Widget subclasses must call this method before attempting to call any other methods. If a browser element has already been attached, then it is replaced with the new element. The old event listeners are removed from the old browser element, and the event listeners are set up on the new browser element.

#### Parameters

elem
  the object's new element

### setEnabled

public void setEnabled(boolean enabled)
Sets whether this widget is enabled.

#### Parameters

enabled
  `true` to enable the widget, `false` to disable it

### setFocus

public void setFocus(boolean focused)
Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

#### Parameters

focused
  whether this widget should take focus or release it

### setTabIndex

public void setTabIndex(int index)
Sets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to `-1` will cause this widget to be removed from the tab order.

#### Parameters

index
  the widget's tab index