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
.
Note that there is no method to retrieve the "currently selected suggestion" in a SuggestBox, because there are points in time where the currently selected suggestion is not defined. For example, if the user types in some text that does not match any of the SuggestBox's suggestions, then the SuggestBox will not have a currently selected suggestion. It is more useful to know when a suggestion has been chosen from the SuggestBox's list of suggestions. A SuggestBox fires SuggestionEvents whenever a suggestion is chosen, and handlers for these events can be added using the addEventHandler(SuggestionHandler) method.
SuggestBox() | Constructor for SuggestBox. |
SuggestBox(SuggestOracle) | Constructor for SuggestBox. |
SuggestBox(SuggestOracle, TextBoxBase) | Constructor for SuggestBox. |
addChangeListener(ChangeListener) | Adds a listener to recieve change events on the SuggestBox's text box. |
addClickListener(ClickListener) | Adds a listener to recieve click events on the SuggestBox's text box. |
addEventHandler(SuggestionHandler) | Adds a handler interface to receive suggestion events. |
addFocusListener(FocusListener) | Adds a listener to recieve focus events on the SuggestBox's text box. |
addKeyboardListener(KeyboardListener) | Adds a listener to recieve keyboard events on the SuggestBox's text box. |
getLimit() | Gets the limit for the number of suggestions that should be displayed for this box. |
getSuggestOracle() | Gets the suggest box's SuggestOracle. |
getTabIndex() | Gets the widget's position in the tab index. |
getText() | Gets this object's text. |
removeChangeListener(ChangeListener) | Removes a previously added listener interface. |
removeClickListener(ClickListener) | Removes a previously added listener interface. |
removeEventHandler(SuggestionHandler) | Removes a previously added handler 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'. |
setFocus(boolean) | Explicitly focus/unfocus this widget. |
setLimit(int) | Sets the limit to the number of suggestions the oracle should provide. |
setPopupStyleName(String) | Sets the style name of the suggestion popup. |
setTabIndex(int) | Sets the widget's position in the tab index. |
setText(String) | Sets this object's text. |
SuggestBox
-1
will cause this widget to
be removed from the tab order.