Textfield

description
description for singleline textfield. create a texfield with

controlP5.addTextfield(theName,theX,theY,theWidth,theHeight); the Textfield implementation for ControlP5 tries its best to imitate the usage and behavior of a terminal, the command line.
+Example
import controlP5.*;
ControlP5 controlP5;

// textfield example by andreas schlegel, 11.02.2009
// for a more advanced example see textfieldAdvanced which 
// demonstrates how to use keepFocus, setText, getText, getTextList,
// clear, setAutoClear, isAutoClear or submit.

String textValue = "";
Textfield myTextfield;

void setup() {
  size(400,400);
  frameRate(25);
  controlP5 = new ControlP5(this);
  myTextfield = controlP5.addTextfield("texting",100,160,200,20);
  myTextfield.setFocus(true);
  controlP5.addTextfield("textValue",100,200,200,20);
}

void draw() {
  background(0);
}


void controlEvent(ControlEvent theEvent) {
  println("controlEvent: accessing a string from controller '"+theEvent.controller().name()+"': "+theEvent.controller().stringValue());
}


public void texting(String theText) {
  // receiving text from controller texting
  println("a textfield event for controller 'texting': "+theText);
}

constructors
Methods
clear ( )
clear the current content of the textfield.
getText ( )
get the current text of the textfield.
getTextList ( )
returns a string array that lists all text lines that have been confirmed with a return.
isAutoClear ( )
returns the current state of the autoClear flag.
isFocus ( )
check if the textfield is active and in focus.
keepFocus ( )
use true as parameter to force the textfield to stay in focus. to go back to normal focus behavior, use false.
setAutoClear ( )
use setAutoClear(false) to not clear the content of the textfield after confirming with return.
setFocus ( )
set the textfield's focus to true or false.
setPasswordMode ( )
set the mode of the textfield to password mode, each character is shown as a "*" like e.g. in online password forms.
setText ( )
setText does set the text of a textfield, but will not broadcast its value. use setText to force the textfield to change its text. you can call setText any time, nevertheless when autoClear is set to true (which is the default), it will NOT work when called from within controlEvent or within a method that has been identified by ControlP5 to forward messages to, when return has been pressed to confirm a textfield.
use setAutoClear(false) to enable setText to be executed for the above case. use yourTextfield.isAutoClear() to check if autoClear is true or false.
setText replaces the current/latest content of a textfield but does NOT overwrite the content. when scrolling through the list of textlines (use key up and down), the previous content that has been replaced will be put back into place again - since it has not been confirmed with return.
setValue ( )
set the value of the textfield and will broadcast the new string value immediately. what is the difference between setValue and setText? setValue does broadcast the value that has been set, setText does not broadcast the value, but only updates the content of a textfield. for further information about how setText works, see the setText documentation.
submit ( )
make the controller execute a return event. submit the current content of the texfield.
usage
Web & Application
related