controlP5
Class CheckBox

java.lang.Object
  extended by controlP5.ControllerGroup
      extended by controlP5.ControlGroup
          extended by controlP5.RadioButton
              extended by controlP5.CheckBox
All Implemented Interfaces:
ControllerInterface, ControlListener, ControlP5Constants

public class CheckBox
extends RadioButton

A checkBox is a multiple-choice radioButton. items are added to a checkBox and can be organized in rows and columns. items of a checkBox are of type Toggle.

See Also:
Toggle
+Example
/**
 * ControlP5 Checkbox
 * an example demonstrating the use of a checkbox in controlP5. 
 * to control a checkbox use:
 * activate(), deactivate(), activateAll(), deactivateAll()
 * toggle(), getState()
 * see the reference for further details
 * by andreas schlegel, 2010
 */
import controlP5.*;

ControlP5 controlP5;

CheckBox checkbox;

int myColorBackground;
void setup() {
  size(400,400);
  smooth();
  controlP5 = new ControlP5(this);
  checkbox = controlP5.addCheckBox("checkBox",20,20);  
  // make adjustments to the layout of a checkbox.
  checkbox.setColorForeground(color(120));
  checkbox.setColorActive(color(255));
  checkbox.setColorLabel(color(128));
  checkbox.setItemsPerRow(3);
  checkbox.setSpacingColumn(30);
  checkbox.setSpacingRow(10);
  // add items to a checkbox.
  checkbox.addItem("0",0);
  checkbox.addItem("10",10);
  checkbox.addItem("50",50);
  checkbox.addItem("100",100);
  checkbox.addItem("200",200);
  checkbox.addItem("5",5);
}

void keyPressed() {
  println(char(1)+" / "+keyCode);
  if(key==' '){
    checkbox.deactivateAll();
  } else {
    for(int i=0;i<6;i++) {
      // check if key 0-5 have been pressed and toggle
      // the checkbox item accordingly.
      if(keyCode==(48 + i)) { 
        // the index of checkbox items start at 0
        checkbox.toggle(i);
        println("toggle "+checkbox.getItem(i).name());
        // also see 
        // checkbox.activate(index);
        // checkbox.deactivate(index);
      }
    }
  }
}

void draw() {
  background(myColorBackground);
  fill(0);
  rect(10,10,150,60);
}

void controlEvent(ControlEvent theEvent) {
  if(theEvent.isGroup()) {
    myColorBackground = 0;
    print("got an event from "+theEvent.group().name()+"\t");
    // checkbox uses arrayValue to store the state of 
    // individual checkbox-items. usage:
    for(int i=0;i

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
 
Constructor Summary
CheckBox(ControlP5 theControlP5, ControllerGroup theParent, java.lang.String theName, int theX, int theY)
          a CheckBox should only be added to controlP5 by using controlP5.addCheckBox()
 
Method Summary
 void activate(int theIndex)
          activate a single checkbox item (by index);
 void activate(java.lang.String theRadioButtonName)
          activate a single checkbox item (by name);
 void activateAll()
          activate all checkBox items.
 void deactivate(int theIndex)
          deactivate a single checkbox item (by index);
 void deactivate(java.lang.String theRadioButtonName)
          deactivate a single checkbox item (by name);
 void toggle(int theIndex)
          toggle a single checkbox item (by index);
 void toggle(java.lang.String theRadioButtonName)
          deactivate a single checkbox item (by name);
 java.lang.String toString()
           
 
Methods inherited from class controlP5.RadioButton
addItem, addItem, controlEvent, deactivateAll, getItem, getState, getState, removeItem, setImage, setImage, setImages, setItemHeight, setItemsPerRow, setItemWidth, setNoneSelectedAllowed, setSize, setSize, setSpacingColumn, setSpacingRow, updateLayout
 
Methods inherited from class controlP5.ControlGroup
activateEvent, addCloseButton, addToXMLElement, arrayValue, getBackgroundHeight, hideBar, isBarVisible, mousePressed, removeCloseButton, setArrayValue, setBackgroundColor, setBackgroundHeight, setBarHeight, showBar, stringValue, 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, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMousePressed, setMoveable, setOpen, setPosition, setTab, setTab, setTab, setUpdate, setVisible, setWidth, show, update, updateAbsolutePosition, updateEvents, updateInternalEvents, valueLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CheckBox

public CheckBox(ControlP5 theControlP5,
                ControllerGroup theParent,
                java.lang.String theName,
                int theX,
                int theY)
a CheckBox should only be added to controlP5 by using controlP5.addCheckBox()

Parameters:
theControlP5 -
theParent -
theName -
theX -
theY -
Method Detail

activateAll

public final void activateAll()
activate all checkBox items.


activate

public final void activate(int theIndex)
activate a single checkbox item (by index);

Overrides:
activate in class RadioButton

deactivate

public final void deactivate(int theIndex)
deactivate a single checkbox item (by index);

Overrides:
deactivate in class RadioButton

toggle

public final void toggle(int theIndex)
toggle a single checkbox item (by index);

Overrides:
toggle in class RadioButton

toggle

public final void toggle(java.lang.String theRadioButtonName)
deactivate a single checkbox item (by name);


activate

public final void activate(java.lang.String theRadioButtonName)
activate a single checkbox item (by name);

Overrides:
activate in class RadioButton

deactivate

public final void deactivate(java.lang.String theRadioButtonName)
deactivate a single checkbox item (by name);

Overrides:
deactivate in class RadioButton

toString

public java.lang.String toString()
Overrides:
toString in class RadioButton


processing library controlP5 by Andreas Schlegel. (c) 2010