libgdx API

com.badlogic.gdx.scenes.scene2d.ui
Class SelectBox

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.ui.Widget
          extended by com.badlogic.gdx.scenes.scene2d.ui.SelectBox
All Implemented Interfaces:
Layout

public class SelectBox
extends Widget

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

Nested Class Summary
static class SelectBox.SelectBoxStyle
          The style for a select box, see SelectBox.
 
Constructor Summary
SelectBox(java.lang.Object[] items, SelectBox.SelectBoxStyle style)
           
SelectBox(java.lang.Object[] items, Skin skin)
           
SelectBox(java.lang.Object[] items, Skin skin, java.lang.String styleName)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.
 float getPrefHeight()
           
 float getPrefWidth()
           
 java.lang.String getSelection()
           
 int getSelectionIndex()
           
 SelectBox.SelectBoxStyle getStyle()
          Returns the select box's style.
 void hideList()
           
 void setItems(java.lang.Object[] objects)
           
 void setSelection(int selection)
          Sets the selected item via it's index
 void setSelection(java.lang.String item)
           
 void setStyle(SelectBox.SelectBoxStyle style)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, layout, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, clearActions, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotate, scale, scale, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setParent, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setVisible, setWidth, setX, setY, setZIndex, size, size, stageToLocalCoordinates, toBack, toFront, toString, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelectBox

public SelectBox(java.lang.Object[] items,
                 Skin skin)

SelectBox

public SelectBox(java.lang.Object[] items,
                 Skin skin,
                 java.lang.String styleName)

SelectBox

public SelectBox(java.lang.Object[] items,
                 SelectBox.SelectBoxStyle style)
Method Detail

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(java.lang.Object[] objects)

draw

public void draw(SpriteBatch 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 - Should be multipied with the actor's alpha, allowing a parent's alpha to affect all children.

setSelection

public void setSelection(int selection)
Sets the selected item via it's index

Parameters:
selection - the selection index

setSelection

public void setSelection(java.lang.String item)

getSelectionIndex

public int getSelectionIndex()
Returns:
the index of the current selection. The top item has an index of 0

getSelection

public java.lang.String getSelection()
Returns:
the string of the currently selected item

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

hideList

public void hideList()

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)