We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › controlP5 Textfield entry problems
Page Index Toggle Pages: 1
controlP5 Textfield entry problems (Read 1352 times)
controlP5 Textfield entry problems
Feb 9th, 2009, 6:41am
 
Getting values from Textfields doesn't work - the included example (ControlP5textfield) produces no output from the texts() function because hitting return/enter clears the field.  i'm not sure what other event would trigger the function.  the mousePressed() function works, but that doesn't help.

If you want to catch input when user hits enter or return, which others have asked about, supposedly you can do this:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=os_libraries_tools;action=display;num=1163646039;start=65#65

but it doesn't work, enter clears the textfield, and stringValue() returns "".  

also there is a lot of confusion between stringValue(), getText(), setValue().  seems like stringValue() and getText() are the same thing, and setValue() should be called setText()?  

the grey last character is a weird way to show the cursor.  the highlighted box already shows the focus.  when you set the value using enter, setValue(), or whatever, the grey character should change back to normal, but it doesn't.  

regardless, how do i get the value of a textfield when i hit return?

Re: controlP5 Textfield entry problems
Reply #1 - Feb 9th, 2009, 6:42am
 
i know a button next to it that calls getText() is a temporary fix, but i don't want to use that.
Re: controlP5 Textfield entry problems
Reply #2 - Feb 10th, 2009, 2:27pm
 
hi,
with 0.3.12 use the following methods to access text from a textfield. each textline that has been confirmed with RETURN, is stored in an array which can be accessed with getTextList(). why is the last character grey? its an indicator of the current cursor position, use left and right cursors to go back and forth, use up and down cursor to "scroll" through the history of textlines of a textfield.

this code snippet was taken from the controlP5textfield example that comes with the download.
Code:

 // using Textfield.getText();
 println("the current text of myTextfield: "+myTextfield.getText());
 // using Textfield.setText();
 myTextfield.setText("changed the text of a textfield");
 println("changing text of myTextfield to: "+myTextfield.getText());
 // using Textfield.getTextList();
 println("the textlist has "+myTextfield.getTextList().length+" items.");
 for(int i=0;i<myTextfield.getTextList().length;i++) {
   println("\t"+myTextfield.getTextList()[i]);
 }


when using the controlEvent method to access the string value of a textfield that has been fired with RETURN:

Code:

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

Re: controlP5 Textfield entry problems
Reply #3 - Feb 10th, 2009, 8:14pm
 
okay, that helps.  i understand that the grey char is a cursor, but from a usability perspective i think it makes more sense to:

- only display cursor when field is active
- be a brighter color

i know i might be being a bit dense about your class structure, but in the controlEvent example you gave, why doesn't this work:
Code:

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

throws: "the function setText(String) does not exist."

theEvent.controller() returns an instance of the controller. Controller, if it's a textfield, has a method called setText().  what am i missing?

Re: controlP5 Textfield entry problems
Reply #4 - Feb 11th, 2009, 1:14pm
 
the class Controller is abstract and is like a blueprint for all Controllers, which includes Textfield. each Controller in ControlP5 extend class Controller. all Controllers share the methods that are provided by class Controller, but each Controller can have its own set of methods, like in the case above. class Controller does not know that Textfield has a method setText, therefore you need to cast theEvent.controller() into a Textfield with ((Textfield)theEvent.controller()) then you can use:
Code:

((Textfield)theEvent.controller()).setText(s)

Page Index Toggle Pages: 1