# setWidth() and setHeight() of Textlabel in ControlP5 not working

**URL:** <https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662>\
**Category:** Libraries\
**Created:** [September 7, 2022, 7:35am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662 "2022-09-07T07:35:03Z")\
**Posts on this page:** 6\
**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:** [September 7, 2022, 7:35am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662/1 "2022-09-07T07:35:03Z")

</div>

Hello.

I am trying to change widh and height of Textlabel in ControlP5.  
But I am not being able to change it. Please Help.

Here is the code from ControlP5 library example. I changed it a little bit.

```auto
import controlP5.*;

ControlP5 cp5;

void setup() {
  size(700,400);
  cp5 = new ControlP5(this);
  
  Textlabel AA = cp5.addTextlabel("label")
                    .setText("A single ControlP5 textlabel")
                    .setPosition(100,50)
                    .setFont(createFont("Georgia",20))
                    .setWidth(100) //not working
                    .setHeight(40) //not working
                    ;
 
 println("width = " + AA.getWidth());
 println("height = " + AA.getHeight());
 
}

void draw() {
  background(0);
}

```

The result is:

```auto
width = 200
height = 20

```

These value of width and height of textlabel doesn’t change no matter what I set using setWidth() and setHeight() functions.

Note: I know changing these seems to be irrelevent. But I need to modify and use these parameters (width and height of textlabel) in my program.

Please Help.

---

<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:** [September 8, 2022, 7:55am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662/2 "2022-09-08T07:55:26Z")

</div>

any comments on this ?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [September 8, 2022, 10:17am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662/3 "2022-09-08T10:17:28Z")

</div>

Hi @Ghostsss,

seems the size is calculated on SingleLineLabel even if it is set…

```auto
  height = theLabel.isMultiline( ) ? theLabel.getHeight( ) : ( int ) ( theGraphics.textAscent( ) + theGraphics.textDescent( ) );
  width = theLabel.isMultiline( ) ? theLabel.getWidth( ) : ( int ) theGraphics.textWidth( theLabel.getTextFormatted( ) );

```

Cheers  
— mnse

---

<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:** [September 9, 2022, 3:46am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662/4 "2022-09-09T03:46:07Z")

</div>

Hi @mnse, Thank you for responding.

Ok, so I tried setting label as multiline using label.setMultiline(true), but processing gave error.

So it seems, maybe we can’t modifty the width of label even though the functions are available. Right ?

And can you please tell me, where you got the code you posted? I searched the source file for label, but couldn’t find it.  
[controlp5/Textlabel.java at master · sojamo/controlp5 · GitHub](https://github.com/sojamo/controlp5/blob/master/src/controlP5/Textlabel.java)

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [September 9, 2022, 7:11am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662/5 "2022-09-09T07:11:18Z")

</div>

Hi @Ghostsss,

Textlabel contains Label which calls [adjust](https://github.com/sojamo/controlp5/blob/1f7cb649865eb8657495b5cfeddd0dbe85d70cac/src/controlP5/ControlFont.java#L161) method from ControlFont and apply it to Label…

Cheers  
— mnse

---

<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:** [September 20, 2022, 12:18am UTC](https://discourse.processing.org/t/setwidth-and-setheight-of-textlabel-in-controlp5-not-working/38662/6 "2022-09-20T00:18:17Z")

</div>

Thank you very much.
