Class ListBox

java.lang.Object
All Implemented Interfaces:
HasAllDragAndDropHandlers, HasAllFocusHandlers, HasAllGestureHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasBlurHandlers, HasChangeHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasFocusHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, HasAttachHandlers, HasHandlers, HasDirectionEstimator, EventListener, Focusable, HasEnabled, HasFocus, HasName, HasVisibility, IsWidget, SourcesChangeEvents, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents

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

  • .gwt-ListBox { }

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);
  }
}

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to its content. This feature is controlled by setDirectionEstimator(boolean), and is off by default.

Use in UiBinder Templates

The items of a ListBox element are laid out in <g:item> elements. Each item contains text that will be added to the list of available items that will be shown, either in the drop down or list. (Note that the tags of the item elements are not capitalized. This is meant to signal that the item is not a runtime object, and so cannot have a ui:field attribute.) It is also possible to explicitly specify item's value using value attribute as shown below.

For example:

 <g:ListBox>
  <g:item>
    first
  </g:item>
  <g:item value='2'>
    second
  </g:item>
 </g:ListBox>
 

Important usage note

Subclasses should neither read nor write option text directly from the option elements created by this class, since such text may need to be wrapped in Unicode bidi formatting characters. They can use the getOptionText and/or setOptionText methods for this purpose instead.