How to have a different font size inside the text field than the font size of its description with ControlP5?

Hi @tea_tree

It is possible if you call the right part of the controller
Please find the code below for your case. Hope it helps :slight_smile:

import controlP5.*;

ControlP5 cp5;

String textValue = "";

void setup() {
  size(700,400);
  
  PFont font = createFont("arial",20);
  PFont controlFont = createFont("arial", 5);
  
  cp5 = new ControlP5(this);
  
  cp5.addTextfield("input")
     .setPosition(20,100)
     .setSize(200,40)
     .setFont(font)
     .setFocus(true)
     .setColor(color(255,0,0))
     ;
  cp5.getController("input").getCaptionLabel().setFont(new ControlFont(controlFont)); //set the font of the caption label.
  //you can also use this same method to set the font for the textarea instead of using .setFont() in the definition of the controller object.
  //cp5.getController("input").getValueLabel().setFont(new ControlFont(font));
                 
}

void draw() {
  background(0);
  fill(255);
  text(cp5.get(Textfield.class,"input").getText(), 360,130);
  text(textValue, 360,180);
}

public void clear() {
  cp5.get(Textfield.class,"textValue").clear();
}

void controlEvent(ControlEvent theEvent) {
  if(theEvent.isAssignableFrom(Textfield.class)) {
    println("controlEvent: accessing a string from controller '"
            +theEvent.getName()+"': "
            +theEvent.getStringValue()
            );
  }
}


public void input(String theText) {
  // automatically receives results from controller input
  println("a textfield event for controller 'input' : "+theText);
}

Best regards

2 Likes