Class WComboBox
- java.lang.Object
-
- Direct Known Subclasses:
WSelectionBox
public class WComboBox extends WFormWidget
A widget that provides a drop-down combo-box control.A combo box provides the user with a set of options, from which one option may be selected.
WComboBox is an MVC view class, using a simple string list model by default. The model may be populated using
addItem()orinsertItem()and the contents can be cleared throughclear(). These methods manipulate the underlyinggetModel().To use the combo box with a custom model instead of the default
WStringListModel, usesetModel().To react to selection events, connect to the
WFormWidget.changed(),activated()orsactivated()signals.At all times, the current selection index is available through
getCurrentIndex()and the current selection text usinggetCurrentText().WComboBoxdoes not have support for auto-completion, this behaviour can be found in theWSuggestionPopup.WComboBox is an
inlinewidget.CSS
The widget corresponds to the HTML
<select>tag and does not provide styling. It can be styled using inline or external CSS as appropriate.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefault
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description WComboBox()Creates an empty combo-box..WComboBox(WContainerWidget parentContainer)Creates an empty combo-box..
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Signal1<java.lang.Integer>activated()Signal emitted when the selection changed.voidaddItem(java.lang.CharSequence text)Adds an option item.voidclear()Clears all items.intfindText(java.lang.CharSequence text, MatchOptions flags)Returns the index of the first item that matches a text.intgetCount()Returns the number of items.intgetCurrentIndex()Returns the currently selected item.WStringgetCurrentText()Returns the text of the currently selected item.WStringgetItemText(int index)Returns the text of a particular item.WAbstractItemModelgetModel()Returns the data model.SelectionModegetSelectionMode()Returns the selection mode.java.lang.StringgetValueText()Returns the current value.voidinsertItem(int index, java.lang.CharSequence text)Inserts an item at the specified position.booleanisNoSelectionEnabled()Returns whether 'no selection' is a valid state.voidrefresh()Refresh the widget.voidremoveItem(int index)Removes the item at the specified position.Signal1<WString>sactivated()Signal emitted when the selection changed.voidsetCurrentIndex(int index)Changes the current selection.protected voidsetFormData(WObject.FormData formData)voidsetItemText(int index, java.lang.CharSequence text)Changes the text for a specified option.voidsetModel(WAbstractItemModel model)Sets the model to be used for the items.voidsetModelColumn(int index)Sets the column in the model to be used for the items.voidsetNoSelectionEnabled(boolean enabled)Enables the ability to have 'no currently selected' item.voidsetValueText(java.lang.String value)Sets the current value.-
Methods inherited from class eu.webtoolkit.jwt.WFormWidget
changed, enableAjax, getLabel, getPlaceholderText, getRealValidator, getTabIndex, getValidator, hasValidatorChanged, isCanReceiveFocus, isReadOnly, propagateSetEnabled, remove, render, setEnabled, setHidden, setPlaceholderText, setReadOnly, setToolTip, setValidator, validate, validated, validatorChanged
-
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
-
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, createDomElement, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getDomChanges, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
-
-
-
Constructor Detail
-
WComboBox
public WComboBox(WContainerWidget parentContainer)
Creates an empty combo-box..
-
WComboBox
public WComboBox()
Creates an empty combo-box..
-
-
Method Detail
-
addItem
public void addItem(java.lang.CharSequence text)
Adds an option item.This adds an item to the underlying model. This requires that the
getModel()is editable.Equivalent to
insertItem()(getCount(),text).
-
getCount
public int getCount()
Returns the number of items.
-
getCurrentIndex
public int getCurrentIndex()
Returns the currently selected item.If no item is currently selected, the method returns -1.
- See Also:
setNoSelectionEnabled(boolean enabled)
-
insertItem
public void insertItem(int index, java.lang.CharSequence text)Inserts an item at the specified position.The item is inserted in the underlying model at position
index. This requires that thegetModel()is editable.- See Also:
addItem(CharSequence text),removeItem(int index)
-
removeItem
public void removeItem(int index)
Removes the item at the specified position.The item is removed from the underlying model. This requires that the
getModel()is editable.- See Also:
insertItem(int index, CharSequence text),clear()
-
setCurrentIndex
public void setCurrentIndex(int index)
Changes the current selection.Specify a value of -1 for
indexto clear the selection.Note: Setting a value of -1 works only if JavaScript is available.
-
setItemText
public void setItemText(int index, java.lang.CharSequence text)Changes the text for a specified option.The text for the item at position
indexis changed. This requires that thegetModel()is editable.
-
getCurrentText
public WString getCurrentText()
Returns the text of the currently selected item.- See Also:
getCurrentIndex(),getItemText(int index)
-
getItemText
public WString getItemText(int index)
Returns the text of a particular item.
-
setModel
public void setModel(WAbstractItemModel model)
Sets the model to be used for the items.The default model is a
WStringListModel.Items in the model can be grouped by setting the
ItemDataRole.Level. The contents is interpreted by Wt::asString, and subsequent items of the same group are rendered as children of a HTML<optgroup>element.- See Also:
setModelColumn(int index)
-
setModelColumn
public void setModelColumn(int index)
Sets the column in the model to be used for the items.The column
indexin the model will be used to retrieve data.The default value is 0.
- See Also:
setModel(WAbstractItemModel model)
-
getModel
public WAbstractItemModel getModel()
Returns the data model.- See Also:
setModel(WAbstractItemModel model)
-
findText
public int findText(java.lang.CharSequence text, MatchOptions flags)Returns the index of the first item that matches a text.
-
getSelectionMode
public SelectionMode getSelectionMode()
Returns the selection mode.Always returns
SelectionMode.Singlefor a combo box, but may returnSelectionMode.Extendedfor a selection box
-
getValueText
public java.lang.String getValueText()
Returns the current value.Returns
getCurrentText()as a String.- Specified by:
getValueTextin classWFormWidget
-
setValueText
public void setValueText(java.lang.String value)
Sets the current value.Sets the current index to the item corresponding to
value.- Specified by:
setValueTextin classWFormWidget
-
refresh
public void refresh()
Description copied from class:WWidgetRefresh the widget.The refresh method is invoked when the locale is changed using
WApplication#setLocale()or when the user hit the refresh button.The widget must actualize its contents in response.
Note: This does not rerender the widget! Calling
refresh()usually does not have any effect (unless you've reimplementedrefresh()to attach to it an effect).- Overrides:
refreshin classWFormWidget
-
clear
public void clear()
Clears all items.Removes all items from the underlying model. This requires that the
getModel()is editable.
-
activated
public Signal1<java.lang.Integer> activated()
Signal emitted when the selection changed.The newly selected item is passed as an argument.
- See Also:
sactivated(),getCurrentIndex()
-
sactivated
public Signal1<WString> sactivated()
Signal emitted when the selection changed.The newly selected text is passed as an argument.
- See Also:
activated(),getCurrentText()
-
setNoSelectionEnabled
public void setNoSelectionEnabled(boolean enabled)
Enables the ability to have 'no currently selected' item.The setting may only be changed for a combo box (and not for a selection box). When enabled, the
getCurrentIndex()may be '-1' also when the combo box contains values. The user can however not select this option, it is thus only useful as a default value.By default, no selection is
falsefor a combo-box andtruefor a selection box.
-
isNoSelectionEnabled
public boolean isNoSelectionEnabled()
Returns whether 'no selection' is a valid state.- See Also:
setNoSelectionEnabled(boolean enabled)
-
setFormData
protected void setFormData(WObject.FormData formData)
- Overrides:
setFormDatain classWObject
-
-