Class ListBox
A widget that presents a list of choices to the user, either as a list box or
as a drop-down list.

CSS Style Rules
Example
public class ListBoxExample implements EntryPoint {
public void onModuleLoad() {
// Make a new list box, adding a few items to it.
ListBox lb = new ListBox();
lb.addItem("foo");
lb.addItem("bar");
lb.addItem("baz");
lb.addItem("toto");
lb.addItem("tintin");
// Make enough room for all five items (setting this value to 1 turns it
// into a drop-down list).
lb.setVisibleItemCount(5);
// Add it to the root panel.
RootPanel.get().add(lb);
}
}
Constructors
Methods
Constructor Detail
ListBox
public ListBox()
Creates an empty list box.
Method Detail
addChangeListener
Adds a listener interface to receive change events.
Parameters
- listener
- the listener interface to add
addItem
public void
addItem(
String item)
Adds an item to the list box.
Parameters
- item
- the text of the item to be added
clear
public void clear()
Removes all items from the list box.
getItemCount
public int getItemCount()
Gets the number of items present in the list box.
Return Value
the number of items
getItemText
public
String getItemText(
int index)
Gets the text associated with the item at the specified index.
Parameters
- index
- the index of the item whose text is to be retrieved
Return Value
the text associated with the item
getSelectedIndex
public int getSelectedIndex()
Gets the currently-selected item. If multiple items are selected, this
method will return the first selected item (
isItemSelected(int)
can be used to query individual items).
Return Value
the selected index, or
-1
if none is selected
getVisibleItemCount
public int getVisibleItemCount()
Gets the number of items that are visible. If only one item is visible,
then the box will be displayed as a drop-down list.
Return Value
the visible item count
insertItem
public void
insertItem(
String item, int idx)
Inserts an item into the list box.
Parameters
- item
- the text of the item to be inserted
- idx
- the index at which to insert it
isItemSelected
public boolean isItemSelected(int itemIndex)
Determines whether an individual list item is selected.
Parameters
- itemIndex
- the index of the item to be tested
Return Value
true
if the item is selected
isMultipleSelect
public boolean isMultipleSelect()
Gets whether this list allows multiple selection.
Return Value
true
if multiple selection is allowed
onBrowserEvent
public void
onBrowserEvent(
Event event)
Parameters
- event
-
removeChangeListener
Removes a previously added listener interface.
Parameters
- listener
- the listener interface to remove
removeItem
public void removeItem(int idx)
Removes the item at the specified index.
Parameters
- idx
- the index of the item to be removed
setMultipleSelect
public void setMultipleSelect(boolean multiple)
Sets whether this list allows multiple selections
Parameters
- multiple
-
true
to allow multiple selections
setSelectedIndex
public void setSelectedIndex(int index)
Sets the currently selected index.
Parameters
- index
- the index of the item to be selected
setVisibleItemCount
public void setVisibleItemCount(int visibleItems)
Sets the number of items that are visible. If only one item is visible,
then the box will be displayed as a drop-down list.
Parameters
- visibleItems
- the visible item count