Class SelectBox<T>

All Implemented Interfaces:
Disableable, Layout

public class SelectBox<T> extends Widget implements Disableable
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.

ChangeListener.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 SelectBox.SelectBoxStyle.background.

Author:
mzechner, Nathan Sweet
  • Constructor Details

  • Method Details

    • setMaxListCount

      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.
    • getMaxListCount

      public int getMaxListCount()
      Returns:
      Max number of items to display when the box is opened, or <= 0 to display them all.
    • setStyle

      public void setStyle(SelectBox.SelectBoxStyle style)
    • getStyle

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

      public void setItems(T... newItems)
      Set the backing Array that makes up the choices available in the SelectBox
    • setItems

      public void setItems(Array<T> newItems)
      Sets the items visible in the select box.
    • clearItems

      public void clearItems()
    • getItems

      public Array<T> getItems()
      Returns the internal items array. If modified, setItems(Array) must be called to reflect the changes.
    • layout

      public void layout()
      Description copied from interface: Layout
      Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() on any each child whose width or height has changed, and calls Layout.validate() on each child. This method should almost never be called directly, instead Layout.validate() should be used.
      Specified by:
      layout in interface Layout
      Overrides:
      layout in class Widget
    • draw

      public void draw(Batch batch, float parentAlpha)
      Description copied from class: Widget
      If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.
      Overrides:
      draw in class Widget
      parentAlpha - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.
    • setAlignment

      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 - See Align.
    • getSelection

      public ArraySelection<T> getSelection()
      Get the set of selected items, useful when multiple items are selected
      Returns:
      a Selection object containing the selected elements
    • getSelected

      @Null public T getSelected()
      Returns the first selected item, or null. For multiple selections use getSelection().
    • setSelected

      public void setSelected(@Null T item)
      Sets the selection to only the passed item, if it is a possible choice, else selects the first item.
    • getSelectedIndex

      public int getSelectedIndex()
      Returns:
      The index of the first selected item. The top item has an index of 0. Nothing selected has an index of -1.
    • setSelectedIndex

      public void setSelectedIndex(int index)
      Sets the selection to only the selected index.
    • setSelectedPrefWidth

      public void setSelectedPrefWidth(boolean selectedPrefWidth)
      When true the pref width is based on the selected item.
    • getSelectedPrefWidth

      public boolean getSelectedPrefWidth()
    • getMaxSelectedPrefWidth

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

      public void setDisabled(boolean disabled)
      Specified by:
      setDisabled in interface Disableable
    • isDisabled

      public boolean isDisabled()
      Specified by:
      isDisabled in interface Disableable
    • getPrefWidth

      public float getPrefWidth()
      Specified by:
      getPrefWidth in interface Layout
      Overrides:
      getPrefWidth in class Widget
    • getPrefHeight

      public float getPrefHeight()
      Specified by:
      getPrefHeight in interface Layout
      Overrides:
      getPrefHeight in class Widget
    • showList

      @Deprecated public void showList()
      Deprecated.
    • showScrollPane

      public void showScrollPane()
    • hideList

      @Deprecated public void hideList()
      Deprecated.
    • hideScrollPane

      public void hideScrollPane()
    • getList

      public List<T> getList()
      Returns the list shown when the select box is open.
    • setScrollingDisabled

      public void setScrollingDisabled(boolean y)
      Disables scrolling of the list shown when the select box is open.
    • getScrollPane

      public SelectBox.SelectBoxScrollPane getScrollPane()
      Returns the scroll pane containing the list that is shown when the select box is open.
    • isOver

      public boolean isOver()
    • getClickListener

      public ClickListener getClickListener()