APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class SelectBox<T>

extends Widget
implements Disableable, Styleable<SelectBox.SelectBoxStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable, com.badlogic.gdx.scenes.scene2d.utils.Disableable
Static Imports
com.badlogic.gdx.scenes.scene2d.actions.Actions.*

A select box (aka a drop-down list) allows a user to choose one of a number of values from a list. When inactive, the selected value is displayed. When activated, it shows the list of values that may be selected.

ChangeEvent is fired when the selectbox selection changes.

The preferred size of the select box is determined by the maximum text bounds of the items and the size of the SelectBoxStyle#background.

Authors
mzechner, Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
SelectBox.SelectBoxScrollPane<T>

The scroll pane shown when a select box is open.

public static class
SelectBox.SelectBoxStyle

The style for a select box, see SelectBox.

Field Summary

Modifier and TypeField and Description
private int
private ClickListener
pack-priv boolean
pack-priv final Array<T>
private float
private float
pack-priv SelectBox.SelectBoxScrollPane<T>
pack-priv boolean
pack-priv final ArraySelection<T>
pack-priv SelectBox.SelectBoxStyle
pack-priv static final Vector2

Constructor Summary

AccessConstructor and Description
public
public
SelectBox(Skin skin, String styleName)

public

Method Summary

Modifier and TypeMethod and Description
public void
public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

protected GlyphLayout
drawItem(Batch batch, BitmapFont font, T item, float x, float y, float width)

protected Drawable
getBackgroundDrawable()

Returns appropriate background drawable from the style based on the current select box state.

public ClickListener
protected Color
getFontColor()

Returns the appropriate label font color from the style based on the current button state.

public Array<T>
getItems()

Returns the internal items array.

public List<T>
getList()

Returns the list shown when the select box is open.

public int
getMaxListCount()

Returns: Max number of items to display when the box is opened, or <= 0 to display them all.

public float
getMaxSelectedPrefWidth()

Returns the pref width of the select box if the widest item was selected, for use when setSelectedPrefWidth(boolean) is true.

public float
public float
public SelectBox.SelectBoxScrollPane<T>
getScrollPane()

Returns the scroll pane containing the list that is shown when the select box is open.

public T
getSelected()

Returns the first selected item, or null.

public int
getSelectedIndex()

Returns: The index of the first selected item.

public boolean
public ArraySelection<T>

Returns:

a Selection object containing the selected elements
getSelection
()

Get the set of selected items, useful when multiple items are selected

public SelectBox.SelectBoxStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the select box's style.

public void
hideList()
Deprecated Use hideScrollPane().

public void
public boolean
public boolean
public void
layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child.

protected SelectBox.SelectBoxScrollPane<T>
newScrollPane()

Allows a subclass to customize the scroll pane shown when the select box is open.

protected void
onHide(Actor scrollPane)

protected void
onShow(Actor scrollPane, boolean below)

public void
setAlignment(int
See Align.
alignment
)

Sets the alignment of the selected item in the select box.

public void
public void
setItems(T... newItems)

Set the backing Array that makes up the choices available in the SelectBox

public void
setItems(Array<T> newItems)

Sets the items visible in the select box.

public void
setMaxListCount(int maxListCount)

Set the max number of items to display when the select box is opened.

public void
setScrollingDisabled(boolean y)

Disables scrolling of the list shown when the select box is open.

public void
setSelected(T item)

Sets the selection to only the passed item, if it is a possible choice, else selects the first item.

public void
setSelectedIndex(int index)

Sets the selection to only the selected index.

public void
setSelectedPrefWidth(boolean selectedPrefWidth)

When true the pref width is based on the selected item.

protected void
setStage(Stage stage)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Called by the framework when this actor or any ascendant is added to a group that is in the stage.

public void
setStyle(SelectBox.SelectBoxStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

public void
showList()
Deprecated Use showScrollPane().

public void
protected String
toString(T item)

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Widget:
getMaxHeightgetMaxWidthgetMinHeightgetMinWidthinvalidateinvalidateHierarchyneedsLayoutpacksetFillParentsetLayoutEnabledsizeChangedvalidate

Field Detail

alignmentback to summary
private int alignment
clickListenerback to summary
private ClickListener clickListener
disabledback to summary
pack-priv boolean disabled
itemsback to summary
pack-priv final Array<T> items
prefHeightback to summary
private float prefHeight
prefWidthback to summary
private float prefWidth
scrollPaneback to summary
pack-priv SelectBox.SelectBoxScrollPane<T> scrollPane
selectedPrefWidthback to summary
pack-priv boolean selectedPrefWidth
selectionback to summary
pack-priv final ArraySelection<T> selection
styleback to summary
pack-priv SelectBox.SelectBoxStyle style
tempback to summary
pack-priv static final Vector2 temp

Constructor Detail

SelectBoxback to summary
public SelectBox(Skin skin)
SelectBoxback to summary
public SelectBox(Skin skin, String styleName)
SelectBoxback to summary
public SelectBox(SelectBox.SelectBoxStyle style)

Method Detail

clearItemsback to summary
public void clearItems()
drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

drawItemback to summary
protected GlyphLayout drawItem(Batch batch, BitmapFont font, T item, float x, float y, float width)
getBackgroundDrawableback to summary
protected Drawable getBackgroundDrawable()

Returns appropriate background drawable from the style based on the current select box state.

Annotations
@Null
getClickListenerback to summary
public ClickListener getClickListener()
getFontColorback to summary
protected Color getFontColor()

Returns the appropriate label font color from the style based on the current button state.

getItemsback to summary
public Array<T> getItems()

Returns the internal items array. If modified, setItems(Array) must be called to reflect the changes.

getListback to summary
public List<T> getList()

Returns the list shown when the select box is open.

getMaxListCountback to summary
public int getMaxListCount()
Returns:int

Max number of items to display when the box is opened, or <= 0 to display them all.

getMaxSelectedPrefWidthback to summary
public float getMaxSelectedPrefWidth()

Returns the pref width of the select box if the widest item was selected, for use when setSelectedPrefWidth(boolean) is true.

getPrefHeightback to summary
public float getPrefHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefHeight.

getPrefWidthback to summary
public float getPrefWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefWidth.

getScrollPaneback to summary
public SelectBox.SelectBoxScrollPane<T> getScrollPane()

Returns the scroll pane containing the list that is shown when the select box is open.

getSelectedback to summary
public T getSelected()

Returns the first selected item, or null. For multiple selections use SelectBox#getSelection().

Annotations
@Null
getSelectedIndexback to summary
public int getSelectedIndex()
Returns:int

The index of the first selected item. The top item has an index of 0. Nothing selected has an index of -1.

getSelectedPrefWidthback to summary
public boolean getSelectedPrefWidth()
getSelectionback to summary
public ArraySelection<T> getSelection()

Get the set of selected items, useful when multiple items are selected

Returns:ArraySelection<T>

a Selection object containing the selected elements

getStyleback to summary
public SelectBox.SelectBoxStyle getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the select box's style. Modifying the returned style may not have an effect until setStyle(SelectBoxStyle) is called.

hideListback to summary
public void hideList()

Deprecated

Use hideScrollPane().

Annotations
@Deprecated
hideScrollPaneback to summary
public void hideScrollPane()
isDisabledback to summary
public boolean isDisabled()

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.isDisabled.

isOverback to summary
public boolean isOver()
layoutback to summary
public void layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Doc from com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child. This method should almost never be called directly, instead validate() should be used.

newScrollPaneback to summary
protected SelectBox.SelectBoxScrollPane<T> newScrollPane()

Allows a subclass to customize the scroll pane shown when the select box is open.

onHideback to summary
protected void onHide(Actor scrollPane)
onShowback to summary
protected void onShow(Actor scrollPane, boolean below)
setAlignmentback to summary
public void setAlignment(int alignment)

Sets the alignment of the selected item in the select box. See getList() and List#setAlignment(int) to set the alignment in the list shown when the select box is open.

Parameters
alignment:int

See Align.

setDisabledback to summary
public void setDisabled(boolean disabled)

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.setDisabled.

setItemsback to summary
public void setItems(T... newItems)

Set the backing Array that makes up the choices available in the SelectBox

setItemsback to summary
public void setItems(Array<T> newItems)

Sets the items visible in the select box.

setMaxListCountback to summary
public void setMaxListCount(int maxListCount)

Set the max number of items to display when the select box is opened. Set to 0 (the default) to display as many as fit in the stage height.

setScrollingDisabledback to summary
public void setScrollingDisabled(boolean y)

Disables scrolling of the list shown when the select box is open.

setSelectedback to summary
public void setSelected(T item)

Sets the selection to only the passed item, if it is a possible choice, else selects the first item.

setSelectedIndexback to summary
public void setSelectedIndex(int index)

Sets the selection to only the selected index.

setSelectedPrefWidthback to summary
public void setSelectedPrefWidth(boolean selectedPrefWidth)

When true the pref width is based on the selected item.

setStageback to summary
protected void setStage(Stage stage)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Called by the framework when this actor or any ascendant is added to a group that is in the stage.

setStyleback to summary
public void setStyle(SelectBox.SelectBoxStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

showListback to summary
public void showList()

Deprecated

Use showScrollPane().

Annotations
@Deprecated
showScrollPaneback to summary
public void showScrollPane()
toStringback to summary
protected String toString(T item)
com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class SelectBox.SelectBoxScrollPane<T>

extends ScrollPane
Class Inheritance

The scroll pane shown when a select box is open.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private InputListener
pack-priv final List<T>
pack-priv int
private Actor
pack-priv final SelectBox<T>
private final Vector2
Inherited from com.badlogic.gdx.scenes.scene2d.ui.ScrollPane:
actorAreaamountXamountYcancelTouchFocusdisableXdisableYdraggingPointerfadeAlphafadeAlphaSecondsfadeDelayfadeDelaySecondsfadeScrollBarsflickScrollflingTimeflingTimerhKnobBoundshScrollBoundshScrollOnBottomlastPointmaxXmaxYscrollBarTouchscrollXscrollYsmoothScrollingtouchScrollHtouchScrollVvelocityXvelocityYvisualAmountXvisualAmountYvKnobBoundsvScrollBoundsvScrollOnRight

Constructor Summary

AccessConstructor and Description
public
SelectBoxScrollPane(final SelectBox<T> selectBox)

Method Summary

Modifier and TypeMethod and Description
public void
act(float delta)

Overrides com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.act.

Updates the actor based on time.

public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget group is laid out.

public List<T>
public SelectBox<T>
public void
hide()

protected List<T>
newList()

Allows a subclass to customize the select box list.

protected void
setStage(Stage stage)

Overrides com.badlogic.gdx.scenes.scene2d.Group.setStage.

Called by the framework when this actor or any ascendant is added to a group that is in the stage.

public void
show(Stage stage)

Inherited from com.badlogic.gdx.scenes.scene2d.ui.ScrollPane:
addActoraddActorAfteraddActorAtaddActorBeforeaddCaptureListeneraddScrollListenercancelcancelTouchFocusclampdrawDebugdrawScrollBarsflinggetActorgetFadeScrollBarsgetFlickScrollListenergetMaxXgetMaxYgetMinHeightgetMinWidthgetMouseWheelXgetMouseWheelYgetOverscrollDistancegetPrefHeightgetPrefWidthgetScrollBarHeightgetScrollBarWidthgetScrollHeightgetScrollPercentXgetScrollPercentYgetScrollWidthgetScrollXgetScrollYgetStylegetVariableSizeKnobsgetVelocityXgetVelocityYgetVisualScrollPercentXgetVisualScrollPercentYgetVisualScrollXgetVisualScrollYgetWidgethitisBottomEdgeisDraggingisFlingingisForceScrollXisForceScrollYisLeftEdgeisPanningisRightEdgeisScrollingDisabledXisScrollingDisabledYisScrollXisScrollYisTopEdgelayoutremoveActorremoveActorremoveActorAtscrollToscrollToscrollXscrollYsetActorsetCancelTouchFocussetClampsetFadeScrollBarssetFlickScrollsetFlickScrollTapSquareSizesetFlingTimesetForceScrollsetOverscrollsetScrollBarPositionssetScrollbarsOnTopsetScrollbarsVisiblesetScrollBarTouchsetScrollingDisabledsetScrollPercentXsetScrollPercentYsetScrollXsetScrollYsetSmoothScrollingsetStylesetupFadeScrollBarssetupOverscrollsetVariableSizeKnobssetVelocityXsetVelocityYsetWidgetsmoothScrollupdateVisualScrollvisualScrollXvisualScrollY

Field Detail

hideListenerback to summary
private InputListener hideListener
listback to summary
pack-priv final List<T> list
maxListCountback to summary
pack-priv int maxListCount
previousScrollFocusback to summary
private Actor previousScrollFocus
selectBoxback to summary
pack-priv final SelectBox<T> selectBox
stagePositionback to summary
private final Vector2 stagePosition

Constructor Detail

SelectBoxScrollPaneback to summary
public SelectBoxScrollPane(final SelectBox<T> selectBox)

Method Detail

actback to summary
public void act(float delta)

Overrides com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.act.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.act.

Updates the actor based on time. Typically this is called each frame by Stage#act(float).

The default implementation calls Action#act(float) on each action and removes actions that are complete.

drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget group is laid out.

getListback to summary
public List<T> getList()
getSelectBoxback to summary
public SelectBox<T> getSelectBox()
hideback to summary
public void hide()
newListback to summary
protected List<T> newList()

Allows a subclass to customize the select box list. The default implementation returns a list that delegates List#toString(Object) to SelectBox#toString(Object).

setStageback to summary
protected void setStage(Stage stage)

Overrides com.badlogic.gdx.scenes.scene2d.Group.setStage.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.setStage.

Called by the framework when this actor or any ascendant is added to a group that is in the stage.

showback to summary
public void show(Stage stage)
com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class SelectBox.SelectBoxStyle

extends Object
Class Inheritance

The style for a select box, see SelectBox.
Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
public Drawable
public Drawable
public Drawable
public Drawable
public Color
public BitmapFont
public Color
public List.ListStyle
public Color
public ScrollPane.ScrollPaneStyle

Constructor Summary

AccessConstructor and Description
public
public
SelectBoxStyle(BitmapFont font, Color fontColor, Drawable background, ScrollPane.ScrollPaneStyle scrollStyle, List.ListStyle listStyle)

public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backgroundback to summary
public Drawable background
Annotations
@Null
backgroundDisabledback to summary
public Drawable backgroundDisabled
Annotations
@Null
backgroundOpenback to summary
public Drawable backgroundOpen
Annotations
@Null
backgroundOverback to summary
public Drawable backgroundOver
Annotations
@Null
disabledFontColorback to summary
public Color disabledFontColor
Annotations
@Null
fontback to summary
public BitmapFont font
fontColorback to summary
public Color fontColor
listStyleback to summary
public List.ListStyle listStyle
overFontColorback to summary
public Color overFontColor
Annotations
@Null
scrollStyleback to summary
public ScrollPane.ScrollPaneStyle scrollStyle

Constructor Detail

SelectBoxStyleback to summary
public SelectBoxStyle()
SelectBoxStyleback to summary
public SelectBoxStyle(BitmapFont font, Color fontColor, Drawable background, ScrollPane.ScrollPaneStyle scrollStyle, List.ListStyle listStyle)
SelectBoxStyleback to summary
public SelectBoxStyle(SelectBox.SelectBoxStyle style)