We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello World...I am by no means a JAVA developer but I am pretty stuck here and would love some guidance...I have scoured this forum and the internets looking for a solution.
I am using CP5 to develop a desktop app...I have 6 text fields I would like to use the TAB key to cycle through and clear the text at the same time:
void keyPressed() {
if (keyCode == TAB) {
cp5.get(Textfield.class, "text1").clear();
Here are what my textfields look like text1-text6:
txt1 = cp5.addTextfield("text1")
.setColorCursor(0xff686868)
.setValue("00")
.setPosition(192, 191)
.setSize(42, 18)
.setFocus(true)
.setAutoClear(false)
.setInputFilter(ControlP5.FLOAT)
.setId(1);
I am surprised this hasn't been asked before, any help would be greatly appreciated!
THANKS!
Answers
I dunno how to use that library yet. But I've noticed that your fields are named something like
"text" + index
, right?Make a variable called something like txtFieldIdx. Inside keyPressed() do something like:
As mentioned, dunno whether it's gonna work or not! Good luck! %%-
Brilliant! That works great..how can I have it .setFocus for each of the fields as well when I tab to it?
I am adding a setFocus line but it keeps them all focused:
Thanks for the quick response!
Just a guess, but perhaps you should turn off the focus from the previous Textfield? :-??
Thanks..that works perfectly. I'm sure others will find this most helpful!