# Changing Text of Label in ControlP5

**URL:** https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254
**Category:** Libraries
**Created:** [June 20, 2023, 5:13am UTC](https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254 "2023-06-20T05:13:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ghostsss](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ghostsss/32/16483_2.png) [@Ghostsss](https://discourse.processing.org/u/Ghostsss)
#### Post date: [June 20, 2023, 5:13am UTC](https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254/1 "2023-06-20T05:13:32Z")

</div>

I am using the ControlP5 GUI library.  
I want to change the text displayed in TextLabel when triggered by some other event. For example in the following case when I press the button.

So I tried two methods marked by OPTION 1 and OPTION 2 in the following code.  
Option 2 is working but Option 1 is not working.  
I don’t want to declare a label variable. so how can I make Option 1 work?  
Please Help.

```auto
import controlP5.*;

ControlP5 cp5;

Textlabel myTextlabelA;

void setup() {
  size(700,400);
  cp5 = new ControlP5(this);
  
  myTextlabelA = cp5.addTextlabel("label")
                    .setText("A single ControlP5 textlabel, in yellow.")
                    .setPosition(100,50)
                    .setColorValue(0xffffff00)
                    .setFont(createFont("Georgia",20))
                    ;
  
  cp5.addToggle("AAA").setPosition(200,200).align(CENTER,CENTER,CENTER,CENTER);

}

void draw() {
  background(0);
}

void AAA(int x){
  cp5.getController("label").setText("Value="+x); /// OPTION 1
  //myTextlabelA.setText("Value="+x); /// OPTION 2
}

```

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [June 20, 2023, 7:01am UTC](https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254/2 "2023-06-20T07:01:23Z")

</div>

```auto
void AAA(int x){
  cp5.getController("label").setValueLabel("Value="+x); /// OPTION 1
}

```

---

<div class="post-metadata">

### Author: ![Ghostsss](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ghostsss/32/16483_2.png) [@Ghostsss](https://discourse.processing.org/u/Ghostsss)
#### Post date: [June 20, 2023, 7:06am UTC](https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254/3 "2023-06-20T07:06:09Z")

</div>

Thank you very much.

---

<div class="post-metadata">

### Author: ![Ghostsss](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ghostsss/32/16483_2.png) [@Ghostsss](https://discourse.processing.org/u/Ghostsss)
#### Post date: [June 20, 2023, 7:28am UTC](https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254/4 "2023-06-20T07:28:18Z")

</div>

How to similarly update the text in textarea controller?  
Following code is giving exception.

```auto

import controlP5.*;

ControlP5 cp5;

void setup() {
  size(700,400);
  cp5 = new ControlP5(this);
  
  cp5.addTextarea("label")
                    .setText("A single ControlP5 textlabel, in yellow.")
                    .setPosition(100,50)
                    .setColorValue(0xffffff00)
                    .setFont(createFont("Georgia",20)).setColorBackground(200)
                    ;
  
  cp5.addToggle("AAA").setPosition(200,200).align(CENTER,CENTER,CENTER,CENTER);

}

void draw() {
  background(200);
}

void AAA(int x){
  cp5.getController("label").setValueLabel("Val: "+x);
}

```

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [June 20, 2023, 8:36am UTC](https://discourse.processing.org/t/changing-text-of-label-in-controlp5/42254/5 "2023-06-20T08:36:22Z")

</div>

I don’t think using the controller for textArea will work because the following returns null.

```auto
println(cp5.getController("label")); // returns null

```

` label.setText("Val: "+x);` works ok.
