controlP5
Class ListBox

java.lang.Object
  extended by controlP5.ControllerGroup
      extended by controlP5.ControlGroup
          extended by controlP5.ListBox
All Implemented Interfaces:
ControllerInterface, ControlListener, ControlP5Constants
Direct Known Subclasses:
DropdownList

public class ListBox
extends ControlGroup
implements ControlListener

scrollList, a list of selectable and scrollable items.

+Example
/**
 * ControlP5 ListBox
 * listBox operates the same way as a scrollList, but
 * is optimized for many items (1000+). using a listBox
 * over a scrollList is recommended
 * by andreas schlegel, 2009
 */
 
import controlP5.*;

ControlP5 controlP5;

ListBox l;
int cnt = 0;
void setup() {
  size(400,400);
  frameRate(30);
  controlP5 = new ControlP5(this);
  l = controlP5.addListBox("myList",100,100,120,120);
  l.setItemHeight(15);
  l.setBarHeight(15);

  l.captionLabel().toUpperCase(true);
  l.captionLabel().set("something else");
  l.captionLabel().style().marginTop = 3;
  l.valueLabel().style().marginTop = 3; // the +/- sign
  //l.setBackgroundColor(color(100,0,0));
  for(int i=0;i<80;i++) {
    l.addItem("item "+i,i);
  }
  l.setColorBackground(color(255,128));
  l.setColorActive(color(0,0,255,128));
}

void keyPressed() {
  if(key=='1') {
    // set the height of a listBox should alwyays be a multiple of itemHeight
    l.setHeight(210); 
  } 
  else if(key=='2') {
    // set the height of a listBox should alwyays be a multiple of itemHeight
    l.setHeight(120);
  }
  else if(key=='i') {
    // set the height of a listBoxItem, should alwyays be a fraction of the listBox
    l.setItemHeight(30); 
  } 
  else if(key=='u') {
    // set the height of a listBoxItem, should alwyays be a fraction of the listBox
    l.setItemHeight(10);
    l.setBackgroundColor(color(100,0,0));
  } 
  else if(key=='a') {
    int n = (int)(random(100000));
    l.addItem("item "+n, n);
  } 
  else if(key=='d') {
    l.removeItem("item "+cnt);
    cnt++;
  }
}

void controlEvent(ControlEvent theEvent) {
  // ListBox is if type ControlGroup.
  // 1 controlEvent will be executed, where the event
  // originates from a ControlGroup. therefore
  // you need to check the Event with
  // if (theEvent.isGroup())
  // to avoid an error message from controlP5.
  
  if (theEvent.isGroup()) {
    // an event from a group e.g. scrollList
    println(theEvent.group().value()+" from "+theEvent.group());
  }
}

void draw() {
  background(128);
  // scroll the scroll List according to the mouseX position
  // when holding down SPACE.
  if(keyPressed && key==' ') {
    //l.scroll(mouseX/((float)width)); // scroll taks values between 0 and 1
  }
  if(keyPressed && key==' ') {
    l.setWidth(mouseX);
  }
}





Field Summary
 
Fields inherited from interface controlP5.ControlP5Constants
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL
 
Method Summary
 void actAsPulldownMenu(boolean theValue)
          Enable a ListBox to act as a pulldown menu.
 ListBoxItem addItem(java.lang.String theName, int theValue)
          Adds an item to the ListBox.
 void addToXMLElement(ControlP5XMLElement theElement)
           
 void clear()
          remove all items from a list box
 void controlEvent(ControlEvent theEvent)
          ControlListener is an interface that can be implemented by a custom class.
 void hideScrollbar()
          hide the scrollbar.
 boolean isScrollbarVisible()
          check if the scrollbar is visible.
 ListBoxItem item(int theIndex)
          returns a listBoxItem by index in the list of items.
 ListBoxItem item(java.lang.String theItemName)
          TODO faulty returns a listBoxItem by name.
 void removeItem(java.lang.String theItemName)
          Removes an item from the ListBox using the unique name of the item given when added to the list.
 void scroll(float theValue)
          scroll the scrollList remotely.
 void setColorActive(int theColor)
          set the color for the group when active.
 void setColorBackground(int theColor)
          set the background color of the group.
 void setColorForeground(int theColor)
          set the foreground color of the group.
 void setColorLabel(int theColor)
          set the color of the text label of the group.
 void setColorValue(int theColor)
          set the color of the value label.
 ListBox setHeight(int theHeight)
          set the height of the list box.
 void setItemHeight(int theHeight)
          set the height of list box items.
 ListBox setWidth(int theWidth)
           
 void showScrollbar()
          show the scrollbar.
 
Methods inherited from class controlP5.ControlGroup
activateEvent, addCloseButton, arrayValue, getBackgroundHeight, hideBar, isBarVisible, mousePressed, removeCloseButton, setArrayValue, setBackgroundColor, setBackgroundHeight, setBarHeight, showBar, stringValue, toString, value
 
Methods inherited from class controlP5.ControllerGroup
absolutePosition, add, addCanvas, addDrawable, captionLabel, close, color, continuousUpdateEvents, controller, disableCollapse, draw, enableCollapse, getAsXML, getColor, getHeight, getPickingColor, getTab, getWidth, getWindow, hide, id, init, isCollapse, isMoveable, isOpen, isUpdate, isVisible, isXMLsavable, keyEvent, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, open, parent, position, remove, remove, remove, removeCanvas, setGroup, setGroup, setId, setLabel, setMousePressed, setMoveable, setOpen, setPosition, setTab, setTab, setTab, setUpdate, setVisible, show, update, updateAbsolutePosition, updateEvents, updateInternalEvents, valueLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

hideScrollbar

public void hideScrollbar()
hide the scrollbar.


showScrollbar

public void showScrollbar()
show the scrollbar.


isScrollbarVisible

public boolean isScrollbarVisible()
check if the scrollbar is visible.

Returns:

scroll

public void scroll(float theValue)
scroll the scrollList remotely. values must range from 0 to 1.

Parameters:
theValue -

setItemHeight

public void setItemHeight(int theHeight)
set the height of list box items.

Parameters:
theHeight -

setHeight

public ListBox setHeight(int theHeight)
set the height of the list box.

Overrides:
setHeight in class ControllerGroup
Parameters:
theHeight -

setWidth

public ListBox setWidth(int theWidth)
Overrides:
setWidth in class ControllerGroup

addItem

public ListBoxItem addItem(java.lang.String theName,
                           int theValue)
Adds an item to the ListBox.

Parameters:
theName - String
theValue - int
See Also:
#removeItem(String,int)

removeItem

public void removeItem(java.lang.String theItemName)
Removes an item from the ListBox using the unique name of the item given when added to the list.

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

item

public ListBoxItem item(int theIndex)
returns a listBoxItem by index in the list of items.

Parameters:
theIndex -
Returns:

item

public ListBoxItem item(java.lang.String theItemName)
TODO faulty returns a listBoxItem by name.

Parameters:
theItemName -
Returns:

controlEvent

public void controlEvent(ControlEvent theEvent)
Description copied from interface: ControlListener
ControlListener is an interface that can be implemented by a custom class. add the controlListener to a controller with Controller.addListner()

Specified by:
controlEvent in interface ControlListener
Overrides:
controlEvent in class ControlGroup
Parameters:
theEvent - ControlEvent Controller

actAsPulldownMenu

public void actAsPulldownMenu(boolean theValue)
Enable a ListBox to act as a pulldown menu. Alternatively use class PulldownMenu instead.

Parameters:
theValue -
See Also:
controlP5.PulldownMenu

clear

public void clear()
remove all items from a list box


setColorActive

public void setColorActive(int theColor)
set the color for the group when active.

Specified by:
setColorActive in interface ControllerInterface
Overrides:
setColorActive in class ControllerGroup
Parameters:
theColor - int

setColorForeground

public void setColorForeground(int theColor)
set the foreground color of the group.

Specified by:
setColorForeground in interface ControllerInterface
Overrides:
setColorForeground in class ControllerGroup
Parameters:
theColor - int

setColorBackground

public void setColorBackground(int theColor)
set the background color of the group.

Specified by:
setColorBackground in interface ControllerInterface
Overrides:
setColorBackground in class ControllerGroup
Parameters:
theColor - int

setColorLabel

public void setColorLabel(int theColor)
set the color of the text label of the group.

Specified by:
setColorLabel in interface ControllerInterface
Overrides:
setColorLabel in class ControllerGroup
Parameters:
theColor - int

setColorValue

public void setColorValue(int theColor)
set the color of the value label.

Specified by:
setColorValue in interface ControllerInterface
Overrides:
setColorValue in class ControllerGroup
Parameters:
theColor - int

addToXMLElement

public void addToXMLElement(ControlP5XMLElement theElement)
Specified by:
addToXMLElement in interface ControllerInterface
Overrides:
addToXMLElement in class ControlGroup
Parameters:
theElement - ControlP5XMLElement


processing library controlP5 by Andreas Schlegel. (c) 2010