# ScrollableList (Javadocs: controlP5)
Date: 2014-04-27

controlP5

## Class ScrollableList

- java.lang.Object
- - controlP5.Controller<ScrollableList>
  - - controlP5.ScrollableList

All Implemented Interfaces:
  CDrawable, ControllerInterface<ScrollableList>, ControlListener, ControlP5Constants

    public class ScrollableList
    extends Controller<ScrollableList>
    implements ControlListener

A ScrollableList is a list of vertically aligned items which can be scrolled if required.

+Example
  `

      /**
       * ControlP5 ScrollableList
       *
       * replaces DropdownList and and ListBox.
       * List can be scrolled by dragging the list or using the scroll-wheel.
       *
       * by Andreas Schlegel, 2014
       * www.sojamo.de/libraries/controlp5
       *
       */

      import controlP5.*;
      import java.util.*;

      ControlP5 cp5;

      void setup() {
        size(400, 400);
        cp5 = new ControlP5(this);
        List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
        /* add a ScrollableList, by default it behaves like a DropdownList */
        cp5.addScrollableList("dropdown").setPosition(100, 100).setSize(200, 100).setItemHeight(20).addItems(l);
      }

      void draw() {
        background(240);
      }

      void dropdown(int n) {
        println(n, cp5.get(ScrollableList.class, "dropdown").getItem(n).get("text"));
        List l = Arrays.asList("a-1", "b-1", "c-1", "d-1", "e-1", "f-1", "g-1", "h-1", "i-1", "j-1", "k-1");
        cp5.get(ScrollableList.class, "dropdown").setItems(l);
      }

      void keyPressed() {
        switch(key) {
          case('1'):
          /* make the ScrollableList behave like a ListBox */
          cp5.get(ScrollableList.class, "dropdown").setType(ControlP5.LIST);
          break;
          case('2'):
          /* make the ScrollableList behave like a DropdownList */
          cp5.get(ScrollableList.class, "dropdown").setType(ControlP5.DROPDOWN);
          break;
        }
      }

  `

### Nested Class Summary

Nested Classes
`static class` `ScrollableList.ScrollableListView`

### Field Summary

Fields
`static int` `CHECKBOX`
`static int` `DROPDOWN`
`static int` `LIST`
`static int` `TREE`

### Fields inherited from class controlP5.Controller

`autoHeight, autoSpacing, autoWidth`

### Fields inherited from interface controlP5.ControlP5Constants

`acceptClassList, ACTION_BROADCAST, ACTION_CLICK, ACTION_DRAG, ACTION_ENTER, ACTION_EXIT, ACTION_LEAVE, ACTION_MOVE, ACTION_PRESS, ACTION_PRESSED, ACTION_RELEASE, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTION_WHEEL, ACTIVE, ALL, ALT, AQUA, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BLACK, BLUE, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DONE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FADEIN, FADEOUT, FIELD, FLOAT, FUCHSIA, GRAY, GREEN, grixel, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IDLE, IMAGE, INACTIVE, INCREASE, INTEGER, INVALID, J2D, KEYCONTROL, LEFT, LEFT_OUTSIDE, LIME, LINE, LOAD, MAROON, MENU, METHOD, MOVE, MULTI, MULTIPLES, NAVY, OLIVE, ORANGE, OVER, P2D, P3D, PI, PRESSED, PRINT, PURPLE, RED, RELEASE, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SHIFT, SILVER, SINGLE, SINGLE_COLUMN, SINGLE_ROW, SPRITE, standard56, standard58, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, synt24, TAB, TEAL, THEME_A, THEME_CP52014, THEME_CP5BLUE, THEME_RED, THEME_RETRO, THEME_WHITE, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT, WHITE, YELLOW`

### Constructor Summary

Constructors
Constructor and Description
`ScrollableList(ControlP5 theControlP5, java.lang.String theName)`

### Method Summary

Methods
`java.util.Map<java.lang.String,java.lang.Object>` `addItem(java.lang.String theName, java.lang.Object theValue)` Adds an item to the ScrollableList.
`ScrollableList` `addItems(java.util.List<?> theItems)`
`ScrollableList` `addItems(java.util.List<?> theItems, int theOffset)`
`ScrollableList` `addItems(java.lang.String[] theItems)` adds a list of items from a string array.
`ScrollableList` `clear()`
`void` `controlEvent(ControlEvent theEvent)` controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about value changes.
`int` `getBackgroundColor()`
`int` `getHeight()`
`java.util.Map<java.lang.String,java.lang.Object>` `getItem(int theIndex)` returns a listBoxItem by index form the list of items.
`java.util.Map<java.lang.String,java.lang.Object>` `getItem(java.lang.String theItemName)` TODO faulty returns a listBoxItem by name.
`java.util.List` `getItems()`
`boolean` `isBarVisible()`
`boolean` `isOpen()`
`void` `keyEvent(processing.event.KeyEvent theKeyEvent)`
`ScrollableList` `removeItem(java.lang.String theItemName)` Removes an item from the ScrollableList using the unique name of the item given when added to the list.
`ScrollableList` `setBackgroundColor(int theColor)`
`ScrollableList` `setBarHeight(int theHeight)`
`ScrollableList` `setBarVisible(boolean b)`
`void` `setDirection(int theDirection)`
`ScrollableList` `setItemHeight(int theHeight)`
`ScrollableList` `setItems(java.util.List<?> theItems)`
`ScrollableList` `setItems(java.util.List<?> theItems, int theOffset)`
`ScrollableList` `setItems(java.lang.String[] theItems)`
`ScrollableList` `setOpen(boolean b)`
`ScrollableList` `setScrollSensitivity(float theSensitivity)`
`ScrollableList` `setType(int theType)`
`ScrollableList` `updateDisplayMode(int theMode)`

### Methods inherited from class controlP5.Controller

`add, addCallback, addListener, align, bringToFront, bringToFront, changeValue, continuousUpdateEvents, draw, getAbsolutePosition, getAddress, getArrayValue, getArrayValue, getBehavior, getCaptionLabel, getColor, getControllerPlugList, getControlWindow, getDecimalPrecision, getDefaultValue, getId, getInfo, getLabel, getMax, getMin, getName, getParent, getPickingColor, getPointer, getPosition, getProperty, getProperty, getStringValue, getTab, getValue, getValueLabel, getView, getWidth, getWindow, hide, init, isActive, isBroadcast, isInside, isLabelVisible, isListening, isLock, isMouseOver, isMousePressed, isMoveable, isUpdate, isUserInteraction, isVisible, linebreak, listen, listenerSize, lock, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, plugTo, plugTo, plugTo, plugTo, registerProperty, registerProperty, registerTooltip, remove, remove, removeBehavior, removeCallback, removeCallback, removeListener, removeProperty, removeProperty, setAbsolutePosition, setAddress, setArrayValue, setArrayValue, setBehavior, setBroadcast, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorCaptionLabel, setColorForeground, setColorValueLabel, setDecimalPrecision, setDefaultValue, setGroup, setGroup, setHeight, setId, setImage, setImage, setImages, setImages, setImages, setLabelVisible, setLock, setMax, setMin, setMouseOver, setMousePressed, setMoveable, setParent, setPosition, setPosition, setSize, setSize, setStringValue, setTab, setTab, setUpdate, setUserInteraction, setValue, setValueLabel, setValueSelf, setView, setView, setVisible, setWidth, show, toString, unlock, unplugFrom, unplugFrom, unregisterTooltip, update, updateAbsolutePosition, updateEvents, updateInternalEvents, updateSize`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface controlP5.ControllerInterface

`parent, setColorLabel, setColorValue, setLabel`

### Field Detail

#### CHECKBOX

    public static final int CHECKBOX

See Also:
  Constant Field Values

#### DROPDOWN

    public static final int DROPDOWN

See Also:
  Constant Field Values

#### LIST

    public static final int LIST

See Also:
  Constant Field Values

#### TREE

    public static final int TREE

See Also:
  Constant Field Values

### Constructor Detail

#### ScrollableList

    public ScrollableList(ControlP5 theControlP5,
                  java.lang.String theName)

### Method Detail

#### addItem

    public java.util.Map<java.lang.String,java.lang.Object> addItem(java.lang.String theName,
                                                           java.lang.Object theValue)

Adds an item to the ScrollableList.

Parameters:
  `theName` - String
  `theValue` - int
See Also:
  `controlP5.ListBox#removeItem(String,int)`

#### addItems

    public ScrollableList addItems(java.util.List<?> theItems)

#### addItems

    public ScrollableList addItems(java.util.List<?> theItems,
                          int theOffset)

#### addItems

    public ScrollableList addItems(java.lang.String[] theItems)

adds a list of items from a string array. when iterating through the array, the index of each item will be used as value.

Parameters:
  `theItems` -

#### clear

    public ScrollableList clear()

#### controlEvent

    public void controlEvent(ControlEvent theEvent)

Description copied from interface: `ControlListener`
controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about value changes. Use the CallbackListener to get informed when actions such as pressed, release, drag, etc are performed.

Specified by:
  `controlEvent` in interface `ControlListener`
Parameters:
  `theEvent` - ControlEvent
See Also:
  `CallbackListener`, `CallbackEvent`

#### getBackgroundColor

    public int getBackgroundColor()

#### getHeight

    public int getHeight()

Specified by:
  `getHeight` in interface `ControllerInterface<ScrollableList>`
Overrides:
  `getHeight` in class `Controller<ScrollableList>`
Returns:
  int

#### getItem

    public java.util.Map<java.lang.String,java.lang.Object> getItem(int theIndex)

returns a listBoxItem by index form the list of items.

Parameters:
  `theIndex` -
Returns:

#### getItem

    public java.util.Map<java.lang.String,java.lang.Object> getItem(java.lang.String theItemName)

TODO faulty returns a listBoxItem by name.

Parameters:
  `theItemName` -
Returns:

#### getItems

    public java.util.List getItems()

#### isBarVisible

    public boolean isBarVisible()

#### isOpen

    public boolean isOpen()

#### keyEvent

    public void keyEvent(processing.event.KeyEvent theKeyEvent)

Specified by:
  `keyEvent` in interface `ControllerInterface<ScrollableList>`
Overrides:
  `keyEvent` in class `Controller<ScrollableList>`

#### removeItem

    public ScrollableList removeItem(java.lang.String theItemName)

Removes an item from the ScrollableList using the unique name of the item given when added to the list.

Parameters:
  `theItemName` - String
See Also:
  `ListBox.addItem(String,int)`

#### setBackgroundColor

    public ScrollableList setBackgroundColor(int theColor)

#### setBarHeight

    public ScrollableList setBarHeight(int theHeight)

#### setBarVisible

    public ScrollableList setBarVisible(boolean b)

#### setDirection

    public void setDirection(int theDirection)

#### setItemHeight

    public ScrollableList setItemHeight(int theHeight)

#### setItems

    public ScrollableList setItems(java.util.List<?> theItems)

#### setItems

    public ScrollableList setItems(java.util.List<?> theItems,
                          int theOffset)

#### setItems

    public ScrollableList setItems(java.lang.String[] theItems)

#### setOpen

    public ScrollableList setOpen(boolean b)

#### setScrollSensitivity

    public ScrollableList setScrollSensitivity(float theSensitivity)

#### setType

    public ScrollableList setType(int theType)

#### updateDisplayMode

    public ScrollableList updateDisplayMode(int theMode)