|
GWT 2.1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.FocusWidget
com.google.gwt.user.client.ui.ListBox
public class ListBox
A widget that presents a list of choices to the user, either as a list box or as a drop-down list.
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); } }
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>
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject |
---|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled |
Field Summary |
---|
Fields inherited from class com.google.gwt.user.client.ui.UIObject |
---|
DEBUG_ID_PREFIX |
Constructor Summary | |
---|---|
|
ListBox()
Creates an empty list box in single selection mode. |
|
ListBox(boolean isMultipleSelect)
Creates an empty list box. |
protected |
ListBox(Element element)
This constructor may be used by subclasses to explicitly use an existing element. |
Method Summary | |
---|---|
HandlerRegistration |
addChangeHandler(ChangeHandler handler)
Adds a ChangeEvent handler. |
void |
addChangeListener(ChangeListener listener)
Deprecated. Use addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) instead |
void |
addItem(java.lang.String item)
Adds an item to the list box. |
void |
addItem(java.lang.String item,
java.lang.String value)
Adds an item to the list box, specifying an initial value for the item. |
void |
clear()
Removes all items from the list box. |
int |
getItemCount()
Gets the number of items present in the list box. |
java.lang.String |
getItemText(int index)
Gets the text associated with the item at the specified index. |
java.lang.String |
getName()
Gets the widget's name. |
int |
getSelectedIndex()
Gets the currently-selected item. |
java.lang.String |
getValue(int index)
Gets the value associated with the item at a given index. |
int |
getVisibleItemCount()
Gets the number of items that are visible. |
void |
insertItem(java.lang.String item,
int index)
Inserts an item into the list box. |
void |
insertItem(java.lang.String item,
java.lang.String value,
int index)
Inserts an item into the list box, specifying an initial value for the item. |
boolean |
isItemSelected(int index)
Determines whether an individual list item is selected. |
boolean |
isMultipleSelect()
Gets whether this list allows multiple selection. |
protected void |
onEnsureDebugId(java.lang.String baseID)
Affected Elements: -item# = the option at the specified index. |
void |
removeChangeListener(ChangeListener listener)
Deprecated. Use the HandlerRegistration.removeHandler()
method on the object returned by addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) instead |
void |
removeItem(int index)
Removes the item at the specified index. |
void |
setItemSelected(int index,
boolean selected)
Sets whether an individual list item is selected. |
void |
setItemText(int index,
java.lang.String text)
Sets the text associated with the item at a given index. |
void |
setMultipleSelect(boolean multiple)
Deprecated. use ListBox(boolean) instead |
void |
setName(java.lang.String name)
Sets the widget's name. |
void |
setSelectedIndex(int index)
Sets the currently selected index. |
void |
setValue(int index,
java.lang.String value)
Sets the value associated with the item at a given index. |
void |
setVisibleItemCount(int visibleItems)
Sets the number of items that are visible. |
static ListBox |
wrap(Element element)
Creates a ListBox widget that wraps an existing <select> element. |
Methods inherited from class com.google.gwt.user.client.ui.Widget |
---|
addAttachHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.google.gwt.event.shared.HasHandlers |
---|
fireEvent |
Constructor Detail |
---|
public ListBox()
public ListBox(boolean isMultipleSelect)
setMultipleSelect(boolean)
.
isMultipleSelect
- specifies if multiple selection is enabledprotected ListBox(Element element)
element
- the element to be usedMethod Detail |
---|
public static ListBox wrap(Element element)
RootPanel.detachNow(Widget)
.
element
- the element to be wrapped
public HandlerRegistration addChangeHandler(ChangeHandler handler)
HasChangeHandlers
ChangeEvent
handler.
addChangeHandler
in interface HasChangeHandlers
handler
- the change handler
HandlerRegistration
used to remove this handler@Deprecated public void addChangeListener(ChangeListener listener)
addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler)
instead
SourcesChangeEvents
addChangeListener
in interface SourcesChangeEvents
listener
- the listener interface to addpublic void addItem(java.lang.String item)
addItem(item, item)
item
- the text of the item to be addedpublic void addItem(java.lang.String item, java.lang.String value)
item
- the text of the item to be addedvalue
- the item's value, to be submitted if it is part of a
FormPanel
; cannot be null
public void clear()
public int getItemCount()
public java.lang.String getItemText(int index)
index
- the index of the item whose text is to be retrieved
java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic java.lang.String getName()
HasName
getName
in interface HasName
public int getSelectedIndex()
isItemSelected(int)
can be used to query individual items).
-1
if none is selectedpublic java.lang.String getValue(int index)
index
- the index of the item to be retrieved
java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic int getVisibleItemCount()
public void insertItem(java.lang.String item, int index)
insertItem(item, item, index)
item
- the text of the item to be insertedindex
- the index at which to insert itpublic void insertItem(java.lang.String item, java.lang.String value, int index)
item
- the text of the item to be insertedvalue
- the item's value, to be submitted if it is part of a
FormPanel
.index
- the index at which to insert itpublic boolean isItemSelected(int index)
index
- the index of the item to be tested
true
if the item is selected
java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic boolean isMultipleSelect()
true
if multiple selection is allowed@Deprecated public void removeChangeListener(ChangeListener listener)
HandlerRegistration.removeHandler()
method on the object returned by addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler)
instead
SourcesChangeEvents
removeChangeListener
in interface SourcesChangeEvents
listener
- the listener interface to removepublic void removeItem(int index)
index
- the index of the item to be removed
java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic void setItemSelected(int index, boolean selected)
Note that setting the selection programmatically does not cause
the ChangeHandler.onChange(ChangeEvent)
event to be fired.
index
- the index of the item to be selected or unselectedselected
- true
to select the item
java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic void setItemText(int index, java.lang.String text)
index
- the index of the item to be settext
- the item's new text
java.lang.IndexOutOfBoundsException
- if the index is out of range@Deprecated public void setMultipleSelect(boolean multiple)
ListBox(boolean)
instead
ListBox(boolean)
constructor. Using this method can spuriously
fail on Internet Explorer 6.0.
multiple
- true
to allow multiple selectionspublic void setName(java.lang.String name)
HasName
setName
in interface HasName
name
- the widget's new namepublic void setSelectedIndex(int index)
setItemSelected(int, boolean)
to select multiple items at a time.
Note that setting the selected index programmatically does not
cause the ChangeHandler.onChange(ChangeEvent)
event to be fired.
index
- the index of the item to be selectedpublic void setValue(int index, java.lang.String value)
FormPanel
.
index
- the index of the item to be setvalue
- the item's new value; cannot be null
java.lang.IndexOutOfBoundsException
- if the index is out of rangepublic void setVisibleItemCount(int visibleItems)
visibleItems
- the visible item countprotected void onEnsureDebugId(java.lang.String baseID)
onEnsureDebugId
in class UIObject
baseID
- the base ID used by the main elementUIObject.onEnsureDebugId(String)
|
GWT 2.1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |