public class ListBox extends FocusWidget implements SourcesChangeEvents, HasChangeHandlers, HasName, HasDirectionEstimator
setDirectionEstimator(boolean)
,
and is off by default.
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>
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
Modifier and Type | Field and Description |
---|---|
static DirectionEstimator |
DEFAULT_DIRECTION_ESTIMATOR |
DEBUG_ID_PREFIX
Modifier | Constructor and Description |
---|---|
|
ListBox()
Creates an empty list box in single selection mode.
|
|
ListBox(boolean isMultipleSelect)
Deprecated.
use
setMultipleSelect(boolean) instead. |
protected |
ListBox(Element element)
This constructor may be used by subclasses to explicitly use an existing
element.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addChangeHandler(ChangeHandler handler)
Adds a
ChangeEvent handler. |
void |
addChangeListener(ChangeListener listener)
Deprecated.
|
void |
addItem(String item)
Adds an item to the list box.
|
void |
addItem(String item,
HasDirection.Direction dir)
Adds an item to the list box, specifying its direction.
|
void |
addItem(String item,
HasDirection.Direction dir,
String value)
Adds an item to the list box, specifying its direction and an initial value
for the item.
|
void |
addItem(String item,
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.
|
DirectionEstimator |
getDirectionEstimator()
Returns the
DirectionEstimator object. |
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.
|
String |
getName()
Gets the widget's name.
|
protected String |
getOptionText(OptionElement option)
Retrieves the text of an option element.
|
int |
getSelectedIndex()
Gets the currently-selected item.
|
String |
getSelectedItemText()
Gets the text for currently selected item.
|
String |
getSelectedValue()
Gets the value for currently selected item.
|
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(String item,
HasDirection.Direction dir,
int index)
Inserts an item into the list box, specifying its direction.
|
void |
insertItem(String item,
HasDirection.Direction dir,
String value,
int index)
Inserts an item into the list box, specifying its direction and an initial
value for the item.
|
void |
insertItem(String item,
int index)
Inserts an item into the list box.
|
void |
insertItem(String item,
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(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 |
setDirectionEstimator(boolean enabled)
Toggles on / off direction estimation.
|
void |
setDirectionEstimator(DirectionEstimator directionEstimator)
Sets the
DirectionEstimator object. |
void |
setItemSelected(int index,
boolean selected)
Sets whether an individual list item is selected.
|
void |
setItemText(int index,
String text)
Sets the text associated with the item at a given index.
|
void |
setItemText(int index,
String text,
HasDirection.Direction dir)
Sets the text associated with the item at a given index.
|
void |
setMultipleSelect(boolean multiple)
Sets whether this list allows multiple selections.
|
void |
setName(String name)
Sets the widget's name.
|
protected void |
setOptionText(OptionElement option,
String text,
HasDirection.Direction dir)
Sets the text of an option element.
|
void |
setSelectedIndex(int index)
Sets the currently selected index.
|
void |
setValue(int index,
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.
|
addBlurHandler, addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addFocusHandler, addFocusListener, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, getFocusImpl, getTabIndex, isEnabled, onAttach, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setEnabled, setFocus, setTabIndex
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
fireEvent
public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR
public ListBox()
@Deprecated public ListBox(boolean isMultipleSelect)
setMultipleSelect(boolean)
instead.isMultipleSelect
- specifies if multiple selection is enabledprotected ListBox(Element element)
element
- the element to be usedpublic static ListBox wrap(Element element)
RootPanel.detachNow(Widget)
.element
- the element to be wrappedpublic HandlerRegistration addChangeHandler(ChangeHandler handler)
HasChangeHandlers
ChangeEvent
handler.addChangeHandler
in interface HasChangeHandlers
handler
- the change handlerHandlerRegistration
used to remove this handler@Deprecated public void addChangeListener(ChangeListener listener)
addChangeHandler(com.google.gwt.event.dom.client.ChangeHandler)
insteadSourcesChangeEvents
addChangeListener
in interface SourcesChangeEvents
listener
- the listener interface to addpublic void addItem(String item)
addItem(item, item)
item
- the text of the item to be addedpublic void addItem(String item, HasDirection.Direction dir)
addItem(item, dir, item)
item
- the text of the item to be addeddir
- the item's directionpublic void addItem(String item, 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 addItem(String item, HasDirection.Direction dir, String value)
item
- the text of the item to be addeddir
- the item's directionvalue
- the item's value, to be submitted if it is part of a
FormPanel
; cannot be null
public void clear()
public DirectionEstimator getDirectionEstimator()
HasDirectionEstimator
DirectionEstimator
object.getDirectionEstimator
in interface HasDirectionEstimator
public int getItemCount()
public String getItemText(int index)
index
- the index of the item whose text is to be retrievedIndexOutOfBoundsException
- if the index is out of rangepublic String getSelectedItemText()
null
if none is selectedpublic int getSelectedIndex()
isItemSelected(int)
can be used to query individual items).-1
if none is selectedpublic String getValue(int index)
index
- the index of the item to be retrievedIndexOutOfBoundsException
- if the index is out of rangepublic String getSelectedValue()
null
if none is selectedpublic int getVisibleItemCount()
public void insertItem(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(String item, HasDirection.Direction dir, int index)
insertItem(item, dir, item, index)
item
- the text of the item to be inserteddir
- the item's directionindex
- the index at which to insert itpublic void insertItem(String item, String value, int index)
insertItem(item, null, value, 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 void insertItem(String item, HasDirection.Direction dir, String value, int index)
item
- the text of the item to be inserteddir
- the item's direction. If null
, the item is displayed in
the widget's overall direction, or, if a direction estimator has
been set, in the item's estimated direction.value
- 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 testedtrue
if the item is selectedIndexOutOfBoundsException
- 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)
insteadSourcesChangeEvents
removeChangeListener
in interface SourcesChangeEvents
listener
- the listener interface to removepublic void removeItem(int index)
index
- the index of the item to be removedIndexOutOfBoundsException
- if the index is out of rangepublic void setDirectionEstimator(boolean enabled)
setDirectionEstimator(com.google.gwt.i18n.shared.DirectionEstimator)
.setDirectionEstimator
in interface HasDirectionEstimator
enabled
- Whether to enable direction estimation. If true
,
sets the DirectionEstimator
object to a default
DirectionEstimator
.public void setDirectionEstimator(DirectionEstimator directionEstimator)
DirectionEstimator
object.
Note: this does not affect the direction of already-existing content.setDirectionEstimator
in interface HasDirectionEstimator
directionEstimator
- The DirectionEstimator
to be set. null
means turning off direction estimation.public 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 itemIndexOutOfBoundsException
- if the index is out of rangepublic void setItemText(int index, String text)
index
- the index of the item to be settext
- the item's new textIndexOutOfBoundsException
- if the index is out of rangepublic void setItemText(int index, String text, HasDirection.Direction dir)
index
- the index of the item to be settext
- the item's new textdir
- the item's direction.IndexOutOfBoundsException
- if the index is out of rangepublic void setMultipleSelect(boolean multiple)
multiple
- true
to allow multiple selectionspublic void setName(String name)
HasName
public 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, String value)
FormPanel
.index
- the index of the item to be setvalue
- the item's new value; cannot be null
IndexOutOfBoundsException
- if the index is out of rangepublic void setVisibleItemCount(int visibleItems)
visibleItems
- the visible item countprotected String getOptionText(OptionElement option)
setOptionText(com.google.gwt.dom.client.OptionElement, java.lang.String, com.google.gwt.i18n.client.HasDirection.Direction)
and was wrapped with Unicode bidi formatting
characters, also removes those additional formatting characters.option
- an option elementprotected void onEnsureDebugId(String baseID)
onEnsureDebugId
in class UIObject
baseID
- the base ID used by the main elementUIObject.onEnsureDebugId(String)
protected void setOptionText(OptionElement option, String text, HasDirection.Direction dir)
BIDI_ATTR_NAME
custom attribute.option
- an option elementtext
- text to be set to the elementdir
- the text's direction. If null
and direction estimation
is turned off, direction is ignored.Copyright © 2018. All rights reserved.