Search code examples
gwtlistboxsuggestbox

Suggest Box, List Box and Scroll Bar


I am able to create a ListBox and SuggestionBox as well in GWT but I want to integrate both of them or can say I want to create a ListBox in GWT which also give me Suggestion same as like Browsers Navigation widget.

Here is the Suggestion Box :

 MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();  
 oracle.add("A");
 oracle.add("AB");
 oracle.add("ABC");
 SuggestBox suggestionBox = new SuggestBox(oracle);

Here is the ListBox :

 private ListBox test;
 test = new ListBox();
 test.addItem("" + "A");
 test.addItem("" + "AB");
 test.addItem("" + "ABC");

Want to merge both this that will give me a List Box with suggestion.

Is it Possible ? If yes, then How ?


Solution

  • You can't merge them.

    If you want to auto-fill the box with the first option (like browsers do in navigation), you need to add a KeyUpHandler to your SuggestBox. In this handler check if there are items that match the letters which a user typed in, and then autofills the box with the first item you find.

    Remember to set the cursor position back to where it was after auto-filling an item, or your users will be unhappy.