# controlP5: controller already exists with RadioButton with same options

**URL:** https://discourse.processing.org/t/controlp5-controller-already-exists-with-radiobutton-with-same-options/17084
**Category:** Libraries
**Created:** [January 14, 2020, 5:09pm UTC](https://discourse.processing.org/t/controlp5-controller-already-exists-with-radiobutton-with-same-options/17084 "2020-01-14T17:09:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [January 14, 2020, 5:09pm UTC](https://discourse.processing.org/t/controlp5-controller-already-exists-with-radiobutton-with-same-options/17084/1 "2020-01-14T17:09:45Z")

</div>

Hi! I think I solved this in the past but can’t remember how atm. The code:

```auto
import controlP5.*;

ControlP5 cp5;

void setup() {
  cp5 = new ControlP5(this);
  RadioButton r1 = cp5.addRadioButton("foo")
    .setPosition(0, 0)
    .addItem("x", 1)
    .addItem("y", 2); 
  RadioButton r2 = cp5.addRadioButton("bar")
    .setPosition(50, 0)
    .addItem("x", 1)
    .addItem("y", 2); 
}
void draw() { }

```

The problem is that only one RadioButton is shown because it doesn’t like having more buttons with the same name. The error:

```auto
Jan 14, 2020 6:00:45 PM controlP5.ControlP5 checkName
WARNING: Controller with name "/x" already exists. overwriting reference of existing controller.
Jan 14, 2020 6:00:45 PM controlP5.ControlP5 checkName
WARNING: Controller with name "/y" already exists. overwriting reference of existing controller.

```

This issue is somewhat related.

> [@Controlp5 - Multiple buttons that use one function](https://discourse.processing.org/t/controlp5-multiple-buttons-that-use-one-function/4638):
>
> So let’s say I had a class that’s display was a button. How would I make it so that all of these classes’ buttons point to one function. e.g. //In my class: button = cp5.addButton("doThis"); //global scope: void doThis() { print("Hello, world!"); } //the error would obviously be this: Oct 19, 2018 3:52:03 PM controlP5.ControlP5 checkName WARNING: Controller with name "/doThis" already exists. overwriting reference of existing controller. I understand why I get an error but I can’t thin…

One ugly fix is to rename `x` and `y` to something like `x0`, `y0`, `x1`, `y1`. Was there a different way to give buttons unique ids but repeating labels?

Thank you 🙂

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [January 14, 2020, 5:22pm UTC](https://discourse.processing.org/t/controlp5-controller-already-exists-with-radiobutton-with-same-options/17084/2 "2020-01-14T17:22:01Z")

</div>

Mmm… not clean but the gui looks right:

```auto
  RadioButton r1 = cp5.addRadioButton("foo")
    .setPosition(0, 0)
    .addItem("x0", 1)
    .addItem("y0", 2); 
  r1.getItem(0).setLabel("x");
  r1.getItem(1).setLabel("y");
    
  RadioButton r2 = cp5.addRadioButton("bar")
    .setPosition(50, 0)
    .addItem("x1", 1)
    .addItem("y1", 2);
  r2.getItem(0).setLabel("x");
  r2.getItem(1).setLabel("y");
}

```

Or a tiny bit more generic:

```auto
  RadioButton r1 = cp5.addRadioButton("foo")
    .setPosition(0, 0)
    .addItem("x0", 1)
    .addItem("y0", 2); 
  for(Toggle t : r1.getItems()) {
    t.setLabel(t.getLabel().substring(0, 1));
  }
    
  RadioButton r2 = cp5.addRadioButton("bar")
    .setPosition(50, 0)
    .addItem("x1", 1)
    .addItem("y1", 2);
  for(Toggle t : r2.getItems()) {
    t.setLabel(t.getLabel().substring(0, 1));
  }

```
