Class SuggestBox
A
SuggestBox is a text box or text area which displays a
pre-configured set of selections that match the user's input.
Each
SuggestBox is associated with a single
SuggestOracle.
The
SuggestOracle is used to provide a set of selections given a
specific query string.
By default, the SuggestBox uses a MultiWordSuggestOracle as
its oracle. Below we show how a MultiWordSuggestOracle can be
configured:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
oracle.add("Cat");
oracle.add("Dog");
oracle.add("Horse");
oracle.add("Canary");
SuggestBox box = new SuggestBox(oracle);
Using the example above, if the user types "C" into the text widget, the
oracle will configure the suggestions with the "Cat" and "Canary"
suggestions. Specifically, whenever the user types a key into the text
widget, the value is submitted to the
MultiWordSuggestOracle
.

CSS Style Rules
- .gwt-SuggestBox { the suggest box itself }
- .gwt-SuggestBoxPopup { the suggestion popup }
- .gwt-SuggestBoxPopup .item { an unselected suggestion }
- .gwt-SuggestBoxPopup .item-selected { a selected suggestion }
Constructors
Methods
See Also
SuggestOracle, MultiWordSuggestOracle, TextBoxBase
Constructor Detail
SuggestBox
public SuggestBox()
Constructor for
SuggestBox. Creates a
MultiWordSuggestOracle and
TextBox to use with this
SuggestBox.
SuggestBox
Constructor for
SuggestBox. Creates a
TextBox to use with
this
SuggestBox.
Parameters
- oracle
- the oracle for this
SuggestBox
SuggestBox
Constructor for
SuggestBox. The text box will be removed from it's
current location and wrapped by the
SuggestBox.
Parameters
- oracle
- supplies suggestions based upon the current contents of the
text widget
- box
- the text widget
Method Detail
addChangeListener
Adds a listener interface to receive change events.
Parameters
- listener
- the listener interface to add
addClickListener
Adds a listener interface to receive click events.
Parameters
- listener
- the listener interface to add
addFocusListener
Adds a listener interface to receive mouse events.
Parameters
- listener
- the listener interface to add
addKeyboardListener
Adds a listener interface to receive keyboard events.
Parameters
- listener
- the listener interface to add
getLimit
public final int getLimit()
Gets the limit for the number of suggestions that should be displayed for
this box. It is up to the current
SuggestOracle to enforce this
limit.
Return Value
the limit for the number of suggestions
getSuggestOracle
Gets the suggest box's
SuggestOracle.
Return Value
the
SuggestOracle
getTabIndex
public int getTabIndex()
Gets the widget's position in the tab index.
Return Value
the widget's tab index
getText
Gets this object's text.
Return Value
the object's text
removeChangeListener
Removes a previously added listener interface.
Parameters
- listener
- the listener interface to remove
removeClickListener
Removes a previously added listener interface.
Parameters
- listener
- the listener interface to remove
removeFocusListener
Removes a previously added listener interface.
Parameters
- listener
- the listener interface to remove
removeKeyboardListener
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
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
setLimit
public final void setLimit(int limit)
Sets the limit to the number of suggestions the oracle should provide. It
is up to the oracle to enforce this limit.
Parameters
- limit
- the limit to the number of suggestions provided
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
setText
public void
setText(
String text)
Sets this object's text.
Parameters
- text
- the object's new text