com.google.gwt.user.client.ui
Class ListBox

java.lang.Object
  extended bycom.google.gwt.user.client.ui.UIObject
      extended bycom.google.gwt.user.client.ui.Widget
          extended bycom.google.gwt.user.client.ui.FocusWidget
              extended bycom.google.gwt.user.client.ui.ListBox
All Implemented Interfaces:
EventListener, HasFocus, SourcesChangeEvents, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents

public class ListBox
extends FocusWidget
implements SourcesChangeEvents

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

code


Field Summary
 
Fields inherited from class java.lang.Object
typeId, typeName
 
Constructor Summary
ListBox()
          Creates an empty list box.
 
Method Summary
 void addChangeListener(ChangeListener listener)
          Adds a listener interface to receive change events.
 void addItem(String item)
          Adds an item to the list box.
 void clear()
          Removes all items from the list box.
 int getItemCount()
          Gets the number of items present in the list box.
 String getItemText(int index)
          Gets the text associated with the item at the specified index.
 int getSelectedIndex()
          Gets the currently-selected item.
 int getVisibleItemCount()
          Gets the number of items that are visible.
 void insertItem(String item, int idx)
          Inserts an item into the list box.
 boolean isItemSelected(int itemIndex)
          Determines whether an individual list item is selected.
 boolean isMultipleSelect()
          Gets whether this list allows multiple selection.
 void onBrowserEvent(Event event)
          Fired whenever a browser event is received.
 void removeChangeListener(ChangeListener listener)
          Removes a previously added listener interface.
 void removeItem(int idx)
          Removes the item at the specified index.
 void setMultipleSelect(boolean multiple)
          Sets whether this list allows multiple selections
 void setSelectedIndex(int index)
          Sets the currently selected index.
 void setVisibleItemCount(int visibleItems)
          Sets the number of items that are visible.
 
Methods inherited from class com.google.gwt.user.client.ui.FocusWidget
addClickListener, addFocusListener, addKeyboardListener, getTabIndex, isEnabled, removeClickListener, removeFocusListener, removeKeyboardListener, setAccessKey, setEnabled, setFocus, setTabIndex
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onAttach, onDetach, onLoad
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, isVisible, isVisible, removeStyleName, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, finalize, hashCode
 

Constructor Detail

ListBox

public ListBox()
Creates an empty list box.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)
Description copied from interface: SourcesChangeEvents
Adds a listener interface to receive change events.

Specified by:
addChangeListener in interface SourcesChangeEvents
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.

Returns:
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
Returns:
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).

Returns:
the selected index, or -1 if none is selected

isItemSelected

public boolean isItemSelected(int itemIndex)
Determines whether an individual list item is selected.

Parameters:
itemIndex - the index of the item to be tested
Returns:
true if the item 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.

Returns:
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

isMultipleSelect

public boolean isMultipleSelect()
Gets whether this list allows multiple selection.

Returns:
true if multiple selection is allowed

onBrowserEvent

public void onBrowserEvent(Event event)
Description copied from interface: EventListener
Fired whenever a browser event is received.

Specified by:
onBrowserEvent in interface EventListener
Overrides:
onBrowserEvent in class FocusWidget

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Description copied from interface: SourcesChangeEvents
Removes a previously added listener interface.

Specified by:
removeChangeListener in interface SourcesChangeEvents
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


This javadoc distribution was not produced by Google. The official documentation is here.