controlP5

## Class RadioButton

- java.lang.Object
- - controlP5.ControllerGroup<T>
  - - controlP5.ControlGroup<RadioButton>
    - - controlP5.RadioButton

- All Implemented Interfaces:
    ControllerInterface<RadioButton>, ControlListener, ControlP5Constants
  Direct Known Subclasses:
    Radio

      public class RadioButton
      extends ControlGroup<RadioButton>

  A radioButton is a list of toggles that can be turned on or off. radioButton is of type ControllerGroup, therefore a controllerPlug can't be set. this means that an event from a radioButton can't be forwarded to a method other than controlEvent in a sketch. a radioButton has 2 sets of values. radioButton.getValue() returns the value of the active radioButton item. radioButton.getArrayValue() returns a float array that represents the active (1) and inactive (0) items of a radioButton. ControlP5 CheckBox Toggle
  +Example
    `

        /**
        * ControlP5 RadioButton
        *
        *
        * find a list of public methods available for the RadioButton Controller
        * at the bottom of this sketch.
        *
        * by Andreas Schlegel, 2012
        * www.sojamo.de/libraries/controlp5
        *
        */

        import controlP5.*;

        ControlP5 cp5;

        int myColorBackground = color(0,0,0);

        RadioButton r1, r2;

        void setup() {
          size(700,400);

          cp5 = new ControlP5(this);
          r1 = cp5.addRadioButton("radioButton")
                 .setPosition(100,180)
                 .setSize(40,20)
                 .setColorForeground(color(120))
                 .setColorActive(color(255))
                 .setColorLabel(color(255))
                 .setItemsPerRow(5)
                 .setSpacingColumn(50)
                 .addItem("50",1)
                 .addItem("100",2)
                 .addItem("150",3)
                 .addItem("200",4)
                 .addItem("250",5)
                 ;

             for(Toggle t:r1.getItems()) {
               t.getCaptionLabel().setColorBackground(color(255,80));
               t.getCaptionLabel().getStyle().moveMargin(-7,0,0,-3);
               t.getCaptionLabel().getStyle().movePadding(7,0,0,3);
               t.getCaptionLabel().getStyle().backgroundWidth = 45;
               t.getCaptionLabel().getStyle().backgroundHeight = 13;
             }

        }

        void draw() {
          background(myColorBackground);
        }

        void keyPressed() {
          switch(key) {
            case('0'): r1.deactivateAll(); break;
            case('1'): r1.activate(0); break;
            case('2'): r1.activate(1); break;
            case('3'): r1.activate(2); break;
            case('4'): r1.activate(3); break;
            case('5'): r1.activate(4); break;
          }

        }

        void controlEvent(ControlEvent theEvent) {
          if(theEvent.isFrom(r1)) {
            print("got an event from "+theEvent.getName()+"\t");
            for(int i=0;i

    `

- - ### Field Summary

    - ### Fields inherited from interface controlP5.ControlP5Constants

      `acceptClassList, ACTION_BROADCAST, ACTION_CLICK, ACTION_DOUBLE_PRESS, ACTION_DRAG, ACTION_END_DRAG, ACTION_ENTER, ACTION_EXIT, ACTION_LEAVE, ACTION_MOVE, ACTION_PRESS, ACTION_PRESSED, ACTION_RELEASE, ACTION_RELEASE_OUTSIDE, ACTION_RELEASED, ACTION_RELEASEDOUTSIDE, ACTION_START_DRAG, ACTION_WHEEL, ACTIVE, ALL, ALT, AQUA, ARC, ARRAY, BACKSPACE, BASELINE, BITFONT, BLACK, BLUE, BOOLEAN, BOTTOM, BOTTOM_OUTSIDE, CAPTIONLABEL, CENTER, CHECKBOX, COMMANDKEY, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, delimiter, DONE, DOWN, DROPDOWN, 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, JSON, KEYCONTROL, LEFT, LEFT_OUTSIDE, LIME, LINE, LIST, LOAD, MAROON, MENU, METHOD, MOVE, MULTI, MULTIPLES, NAVY, OLIVE, ORANGE, OVER, P2D, P3D, pathdelimiter, PI, PRESS, PRESSED, PRINT, PURPLE, RED, RELEASE, RELEASED, RESET, RIGHT, RIGHT_OUTSIDE, SAVE, SERIALIZED, 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_GREY, THEME_RED, THEME_RETRO, TOP, TOP_OUTSIDE, TRANSITION_WAIT_FADEIN, TREE, TWO_PI, UP, VALUELABEL, VERBOSE, VERTICAL, WAIT, WHITE, YELLOW`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RadioButton(ControlP5 theControlP5, ControllerGroup<?> theParent, java.lang.String theName, int theX, int theY)`
    `RadioButton(ControlP5 theControlP5, java.lang.String theName)` Convenience constructor to extend RadioButton.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `RadioButton` | `activate(int theIndex)` Deactivates all active RadioButton items and only activates the item corresponding to theIndex.
    `RadioButton` | `activate(java.lang.String theName)` Actives an item of the Radio button by name.
    `RadioButton` | `addItem(java.lang.String theName, float theValue)`
    `RadioButton` | `addItem(Toggle theToggle, float theValue)`
    `RadioButton` | `align(int[] a)`
    `RadioButton` | `align(int theX, int theY)`
    `RadioButton` | `alignX(int theX)`
    `RadioButton` | `alignY(int theY)`
    `void` | `controlEvent(ControlEvent theEvent)` controlEvent is called by controlP5's ControlBroadcaster to inform available listeners about value changes.
    `RadioButton` | `deactivate(int theIndex)`
    `RadioButton` | `deactivate(java.lang.String theName)` Deactivates a RadioButton by name and sets the value of the RadioButton to the default value -1.
    `RadioButton` | `deactivateAll()`
    `int[]` | `getAlign()`
    `java.lang.String` | `getInfo()`
    `Toggle` | `getItem(int theIndex)` Gets a radio button item by index.
    `Toggle` | `getItem(java.lang.String theName)`
    `java.util.List<Toggle>` | `getItems()`
    `boolean` | `getState(int theIndex)` Gets the state of an item - this can be true (for on) or false (for off) - by index.
    `boolean` | `getState(java.lang.String theName)` Gets the state of an item - this can be true (for on) or false (for off) - by name.
    `RadioButton` | `hideLabels()`
    `RadioButton` | `plugTo(java.lang.Object theObject)`
    `RadioButton` | `plugTo(java.lang.Object theObject, java.lang.String thePlugName)`
    `RadioButton` | `removeItem(java.lang.String theName)`
    `RadioButton` | `setArrayValue(float[] theArray)` Sets the value for all RadioButton items according to the values of the array passed on.
    `RadioButton` | `setColorLabels(int theColor)`
    `RadioButton` | `setImage(processing.core.PImage theImage)`
    `RadioButton` | `setImage(processing.core.PImage theImage, int theState)`
    `RadioButton` | `setImages(processing.core.PImage theDefaultImage, processing.core.PImage theOverImage, processing.core.PImage theActiveImage)`
    `RadioButton` | `setItemHeight(int theItemHeight)` set the height of a radioButton/checkBox item.
    `RadioButton` | `setItemsPerRow(int theValue)` Items of a radioButton or a checkBox are organized in columns and rows.
    `RadioButton` | `setItemWidth(int theItemWidth)` set the width of a radioButton/checkBox item.
    `RadioButton` | `setLabelPadding(int thePaddingX, int thePaddingY)`
    `RadioButton` | `setNoneSelectedAllowed(boolean theValue)` In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this is true.
    `RadioButton` | `setSize(int theWidth, int theHeight)`
    `RadioButton` | `setSize(processing.core.PImage theImage)`
    `RadioButton` | `setSpacingColumn(int theSpacing)` Sets the spacing in pixels between columns.
    `RadioButton` | `setSpacingRow(int theSpacing)` Sets the spacing in pixels between rows.
    `RadioButton` | `showLabels()`
    `RadioButton` | `toggle(int theIndex)`
    `RadioButton` | `toUpperCase(boolean theValue)`
    `void` | `updateLayout()`

    - ### Methods inherited from class controlP5.ControlGroup

      `activateEvent, addListener, getBackgroundHeight, getBarHeight, listenerSize, mousePressed, removeListener, setBackgroundColor, setBackgroundHeight, setBarHeight, stringValue, toString, updateInternalEvents`

    - ### Methods inherited from class controlP5.ControllerGroup

      `add, addCanvas, addCloseButton, addDrawable, bringToFront, bringToFront, close, continuousUpdateEvents, disableCollapse, draw, enableCollapse, getAbsolutePosition, getAddress, getArrayValue, getArrayValue, getCaptionLabel, getColor, getController, getHeight, getId, getName, getParent, getPickingColor, getPosition, getProperty, getProperty, getStringValue, getTab, getValue, getValueLabel, getWidth, getWindow, hide, hideArrow, hideBar, init, isBarVisible, isCollapse, isMouseOver, isMoveable, isOpen, isUpdate, isVisible, keyEvent, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, open, registerProperty, registerProperty, remove, remove, remove, removeCanvas, removeCloseButton, removeProperty, removeProperty, set, setAbsolutePosition, setAddress, setArrayValue, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorForeground, setColorLabel, setColorValue, setGroup, setGroup, setHeight, setId, setLabel, setMouseOver, setMousePressed, setMoveable, setOpen, setPosition, setPosition, setStringValue, setTab, setTab, setTab, setTitle, setUpdate, setValue, setVisible, setWidth, show, showArrow, showBar, update, updateAbsolutePosition, updateEvents, x, y`

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

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

- - ### Constructor Detail

    - #### RadioButton

          public RadioButton(ControlP5 theControlP5,
                             ControllerGroup<?> theParent,
                             java.lang.String theName,
                             int theX,
                             int theY)

      Parameters:
        `theControlP5` -
        `theParent` -
        `theName` -
        `theX` -
        `theY` -

    - #### RadioButton

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

      Convenience constructor to extend RadioButton.
      Parameters:
        `theControlP5` -
        `theName` -
      +Example
        `

            /**
             * ControlP5 extending Controllers
             *
             * the following example shows how to extend the Controller class to
             * create customizable Controllers. You can either extend the Controller class itself,
             * or any class that extends Controller itself like the Slider, Button, DropdownList, etc.
             *
             * How to:
             *
             * 1) do a super call to the convenience constructor requiring
             * 2 parameter (ControlP5 instance, name)
             *
             * 2) the Controller class has a set of empty methods that allow you to capture
             * inputs from the mouse including
             * onEnter(), onLeave(), onPress(), onRelease(), onClick(), onScroll(int), onDrag()
             * These you can override and include functionality as needed.
             *
             * 3) use method getPointer() to return the local (relative)
             * xy-coordinates of the controller
             *
             * 4) after instantiation custom controllers are treated the same
             * as default controlP5 controllers.
             *
             * by Andreas Schlegel, 2012
             * www.sojamo.de/libraries/controlp5
             *
             */

            import controlP5.*;

            ControlP5 cp5;
            PApplet p;

            void setup() {
              size(400, 400);
              cp5 = new ControlP5(this);

              // create 2 groups to show nesting of custom controllers and
              //
              Group g1 = cp5.addGroup("a").setPosition(0,100).setWidth(180);
              Group g2 = cp5.addGroup("b").setPosition(0,10).setWidth(180);
              g2.moveTo(g1);

              // create 2 custom Controllers from class MyButton
              // MyButton extends Controller and inherits all methods accordingly.
              new MyButton(cp5, "b1").setPosition(0, 0).setSize(180, 200).moveTo(g2);
              new MyButton(cp5, "b2").setPosition(205, 15).setSize(180, 200);

            }

            void draw() {
              background(0);
            }

            // b1 will be called from Controller b1
            public void b1(float theValue) {
              println("yay button "+theValue);
            }

            public void controlEvent(ControlEvent theEvent) {
              println("controlEvent : "+theEvent);
            }

            // Create a custom Controller, please not that
            // MyButton extends Controller,
            // is an indicator for the super class about the type of
            // custom controller to be created.

            class MyButton extends Controller {

              int current = 0xffff0000;

              float a = 128;

              float na;

              int y;

              // use the convenience constructor of super class Controller
              // MyButton will automatically registered and move to the
              // default controlP5 tab.

              MyButton(ControlP5 cp5, String theName) {
                super(cp5, theName);

                // replace the default view with a custom view.
                setView(new ControllerView() {
                  public void display(PGraphics p, Object b) {
                    // draw button background
                    na += (a-na) * 0.1;
                    p.fill(current,na);
                    p.rect(0, 0, getWidth(), getHeight());

                    // draw horizontal line which can be moved on the x-axis
                    // using the scroll wheel.
                    p.fill(0,255,0);
                    p.rect(0,y,width,10);

                    // draw the custom label
                    p.fill(128);
                    translate(0,getHeight()+14);
                    p.text(getName(),0,0);
                    p.text(getName(),0,0);

                  }
                }
                );
              }

              // override various input methods for mouse input control
              void onEnter() {
                cursor(HAND);
                println("enter");
                a = 255;
              }

              void onScroll(int n) {
                println("scrolling");
                y -= n;
                y = constrain(y,0,getHeight()-10);
              }

              void onPress() {
                println("press");
                current = 0xffffff00;
              }

              void onClick() {
                Pointer p1 = getPointer();
                println("clicked at "+p1.x()+", "+p1.y());
                current = 0xffffff00;
                setValue(y);
              }

              void onRelease() {
                println("release");
                current = 0xffffffff;
              }

              void onMove() {
                println("moving "+this+" "+_myControlWindow.getMouseOverList());
              }

              void onDrag() {
                current = 0xff0000ff;
                Pointer p1 = getPointer();
                float dif = dist(p1.px(),p1.py(),p1.x(),p1.y());
                println("dragging at "+p1.x()+", "+p1.y()+" "+dif);
              }

              void onReleaseOutside() {
                onLeave();
              }

              void onLeave() {
                println("leave");
                cursor(ARROW);
                a = 128;
              }
            }

        `

  - ### Method Detail

    - #### activate

          public RadioButton activate(int theIndex)

      Deactivates all active RadioButton items and only activates the item corresponding to theIndex. TODO does not trigger function or value when called by code, fix!
      Parameters:
        `theIndex` -

    - #### activate

          public RadioButton activate(java.lang.String theName)

      Actives an item of the Radio button by name.
      Parameters:
        `theName` -

    - #### addItem

          public RadioButton addItem(java.lang.String theName,
                                     float theValue)

      Parameters:
        `theName` -
        `theValue` -
      Returns:

    - #### addItem

          public RadioButton addItem(Toggle theToggle,
                                     float theValue)

      Parameters:
        `theToggle` -
        `theValue` -
      Returns:

    - #### align

          public RadioButton align(int[] a)

    - #### align

          public RadioButton align(int theX,
                                   int theY)

    - #### alignX

          public RadioButton alignX(int theX)

    - #### alignY

          public RadioButton alignY(int theY)

    - #### controlEvent

          public void controlEvent(ControlEvent theEvent)

      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`
      Overrides:
        `controlEvent` in class `ControlGroup<RadioButton>`
      Parameters:
        `theEvent` - ControlEvent
      See Also:
        `CallbackListener`, `CallbackEvent`

    - #### deactivate

          public RadioButton deactivate(int theIndex)

      Parameters:
        `theIndex` -

    - #### deactivate

          public RadioButton deactivate(java.lang.String theName)

      Deactivates a RadioButton by name and sets the value of the RadioButton to the default value -1.
      Parameters:
        `theName` -

    - #### deactivateAll

          public RadioButton deactivateAll()

    - #### getAlign

          public int[] getAlign()

    - #### getInfo

          public java.lang.String getInfo()

      Overrides:
        `getInfo` in class `ControlGroup<RadioButton>`

    - #### getItem

          public Toggle getItem(int theIndex)

      Gets a radio button item by index.
      Parameters:
        `theIndex` -
      Returns:
        Toggle

    - #### getItem

          public Toggle getItem(java.lang.String theName)

    - #### getItems

          public java.util.List<Toggle> getItems()

    - #### getState

          public boolean getState(int theIndex)

      Gets the state of an item - this can be true (for on) or false (for off) - by index.
      Parameters:
        `theIndex` -
      Returns:
        boolean

    - #### getState

          public boolean getState(java.lang.String theName)

      Gets the state of an item - this can be true (for on) or false (for off) - by name.
      Parameters:
        `theName` -
      Returns:

    - #### hideLabels

          public RadioButton hideLabels()

    - #### plugTo

          public RadioButton plugTo(java.lang.Object theObject)

    - #### plugTo

          public RadioButton plugTo(java.lang.Object theObject,
                                    java.lang.String thePlugName)

    - #### removeItem

          public RadioButton removeItem(java.lang.String theName)

      Parameters:
        `theName` -

    - #### setArrayValue

          public RadioButton setArrayValue(float[] theArray)

      Sets the value for all RadioButton items according to the values of the array passed on. 0 will turn off an item, any other value will turn it on.
      Specified by:
        `setArrayValue` in interface `ControllerInterface<RadioButton>`
      Overrides:
        `setArrayValue` in class `ControllerGroup<RadioButton>`

    - #### setColorLabels

          public RadioButton setColorLabels(int theColor)

    - #### setImage

          public RadioButton setImage(processing.core.PImage theImage)

      Parameters:
        `theImage` -

    - #### setImage

          public RadioButton setImage(processing.core.PImage theImage,
                                      int theState)

      Parameters:
        `theImage` -
        `theState` - use Controller.DEFAULT (background), or Controller.OVER (foreground), or Controller.ACTIVE (active)
      Returns:

    - #### setImages

          public RadioButton setImages(processing.core.PImage theDefaultImage,
                                       processing.core.PImage theOverImage,
                                       processing.core.PImage theActiveImage)

      Parameters:
        `theDefaultImage` -
        `theOverImage` -
        `theActiveImage` -
      Returns:
        RadioButton

    - #### setItemHeight

          public RadioButton setItemHeight(int theItemHeight)

      set the height of a radioButton/checkBox item. by default the height is 11px. in order to recognize a custom height, the itemHeight has to be set before adding items to a radioButton/checkBox.
      Parameters:
        `theItemHeight` -

    - #### setItemsPerRow

          public RadioButton setItemsPerRow(int theValue)

      Items of a radioButton or a checkBox are organized in columns and rows. SetItemsPerRow sets the limit of items per row. items exceeding the limit will be pushed to the next row.
      Parameters:
        `theValue` -

    - #### setItemWidth

          public RadioButton setItemWidth(int theItemWidth)

      set the width of a radioButton/checkBox item. by default the width is 11px. in order to recognize a custom width, the itemWidth has to be set before adding items to a radioButton/checkBox.
      Parameters:
        `theItemWidth` -

    - #### setLabelPadding

          public RadioButton setLabelPadding(int thePaddingX,
                                             int thePaddingY)

    - #### setNoneSelectedAllowed

          public RadioButton setNoneSelectedAllowed(boolean theValue)

      In order to always have 1 item selected, use setNoneSelectedAllowed(false), by default this is true. setNoneSelectedAllowed does not apply when in multipleChoice mode.
      Parameters:
        `theValue` -

    - #### setSize

          public RadioButton setSize(int theWidth,
                                     int theHeight)

      Overrides:
        `setSize` in class `ControlGroup<RadioButton>`

    - #### setSize

          public RadioButton setSize(processing.core.PImage theImage)

    - #### setSpacingColumn

          public RadioButton setSpacingColumn(int theSpacing)

      Sets the spacing in pixels between columns.
      Parameters:
        `theSpacing` -

    - #### setSpacingRow

          public RadioButton setSpacingRow(int theSpacing)

      Sets the spacing in pixels between rows.
      Parameters:
        `theSpacing` -

    - #### showLabels

          public RadioButton showLabels()

    - #### toggle

          public RadioButton toggle(int theIndex)

      Parameters:
        `theIndex` -

    - #### toUpperCase

          public RadioButton toUpperCase(boolean theValue)

    - #### updateLayout

          public void updateLayout()

processing library controlP5 by Andreas Schlegel. (c) 2006-2015