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 setvalue problem
Page Index Toggle Pages: 1
controlp5 textfield setvalue problem (Read 1441 times)
controlp5 textfield setvalue problem
Feb 2nd, 2009, 6:40pm
 
Hi,

I'm trying to use controlp5 to make a little inventory system for the computers at my work.

Everything seems to be going fine, but in trying to combat controlp5's tendency to clear textfields when you press enter, I'm saving the information out to a string and then loading it back in to the textfield after the fact.
It seems though, I'm having a lot of problems with the setValue function.

my Textfield object is called txtModelName in this case.

the following line works:
newComputer.modelName=ComputerList.txtModelName.getText();

but putting the text back in, or any string for that matter, does not work:
ComputerList.txtModelName.setValue("string"); // nope!

exception:  java.lang.reflect.InvocationTargetExceptionERROR. an error occured while forwarding a Controller value
to a method in your program. please check your code for any
possible errors that might occur in this method .
e.g. check for casting errors, possible nullpointers, array overflows ... .
method: controlEvent
exception:  java.lang.reflect.InvocationTargetException


As i understand i should be able to use the setValue function, give it any string, and that the textfield will be updated with that string? what could be going wrong here. Any ideas?
Re: controlp5 textfield setvalue problem
Reply #1 - Feb 3rd, 2009, 1:02pm
 
hi,
the error message indicates that you are trying to set the value of your textfield in controlEvent, which ends up in an endless loop because the textfield gets updated and consequently the textfield will call controlEvent again. to set the value you would need to do so outside of controlEvent, or you download version 0.3.11 and use
Code:

void controlEvent(ControlEvent theEvent) {
 ComputerList.txtModelName.setText("something");
}


best,
andreas
Re: controlp5 textfield setvalue problem
Reply #2 - Feb 3rd, 2009, 4:53pm
 
ah. makes sense. thanks!
Re: controlp5 textfield setvalue problem
Reply #3 - Feb 4th, 2009, 3:20am
 
is there a way to do same thing with sliders, if you want to update their values after they are used?  same issue - you can't use setValue because it causes recursive error.
Re: controlp5 textfield setvalue problem
Reply #4 - Feb 9th, 2009, 5:06am
 
aha, you can use a "cheat" function called setValueLabel().   not pretty but it works.  
Code:

void sliderTest(int _x) {
// snap to increments of 10
// x is the real var, _x is what slider passes in
x = (_x/10)*10;
controlP5.controller("sliderTest").setValueLabel(str(x));
}
Re: controlp5 textfield setvalue problem
Reply #5 - Feb 10th, 2009, 9:10pm
 
@starkes:

i don't think setText() works for your question, does it?  setText() doesn't do anything in controlEvent().  it works outside it.  sojamo?

here is sojamo's example, modified, and you can see that getText() works but setText() doesn't:

Code:

import controlP5.*;
ControlP5 controlP5;

Textfield myTextfield;

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

void draw() {
background(0);
}

void controlEvent(ControlEvent theEvent) {
String s = myTextfield.getText();
println("controlEvent from '"+theEvent.controller().name()+"': "+s);

// this doesn't work!
myTextfield.setText(s);
}

 

Re: controlp5 textfield setvalue problem
Reply #6 - Feb 11th, 2009, 2:08pm
 
with 0.3.11 this worked, with 0.3.12 it didnt. i included an advanced textfield example (ControlP5TextfieldAdvanced) in the latest version 0.3.13 that shows how to setText in controlEvent, it also demonstrates when it will not work. due to inattention i made setText work for 0.3.11 without realizing that this would clear the stringValue of a textfield, hence an empty stringValue did arrive in controlEvent overwriting the actual content with an empty string, not very useful. so i did clean up the textfield class and used the ControlP5TextfieldAdvanced example (included in the latest download) for debugging. honestly, bug fixing controlP5 now that it allows so much flexibility is not fun.
Page Index Toggle Pages: 1