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


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.

import controlP5.*;

ControlP5 cp5;

void setup() {
  cp5 = new ControlP5(this);
  Textlabel AA = cp5.addTextlabel("label")
                    .setText("A single ControlP5 textlabel")
                    .setWidth(100)  //not working
                    .setHeight(40)  //not working
 println("width = "  + AA.getWidth());
 println("height = " + AA.getHeight());

void draw() {

The result is:

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.

any comments on this ?

Hi @Ghostsss,

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

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

— mnse

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/ at master · sojamo/controlp5 · GitHub

Hi @Ghostsss,

Textlabel contains Label which calls adjust method from ControlFont and apply it to Label…

— mnse

1 Like

Thank you very much.