How to change the defauld settings of the label of a textfield using Controlp5 library

edited October 2015 in Library Questions

I would like to have the label of a Controlp5 Textfield set to LowerCase and placed left of the Textfield.

t.toUpperCase(false); // t being the textfield does not work.

Tanks

Answers

  • Answer ✓

    Hi, since this might not be immediately obvious, here an example of how to modify a Caption Label:

    import controlP5.*;
    ControlP5 cp5;
    
    void setup(){
      size(700,400);
    
      cp5 = new ControlP5(this);
    
      PFont font = createFont("arial",20);
    
      Textfield t = cp5.addTextfield("textValue")
            .setPosition(120,170)
            .setSize(200,40)
            .setFont(font);
    
      Label label = t.getCaptionLabel(); 
      label.setFont(font);
      label.toUpperCase(false);
      // in order to update the upperCase state, you need to invoke setText()
      label.setText("textValue"); 
      label.align(ControlP5.LEFT_OUTSIDE, CENTER);
      label.getStyle().setPaddingLeft(-10);
    }
    
    void draw(){
      background(0);
    }
    
  • edited October 2015

    Thank you for your quick reply.

    CENTER in the line: label.align(ControlP5.LEFT_OUTSIDE, CENTER); does not have effect and can be replaced by any variable. Why?

    I have a few more questions related to a Textfield.

    1) How to change the bordercolor and borderwidth of the Textfield?

    2) Is it possible to CENTER the entered text in the Textfield?

    Thanks in advance for your help.

    PS: Do I have to post the Textfield questions as a NEW question.

Sign In or Register to comment.