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 & HelpSyntax Questions › Letting a TextField loose Focus again
Page Index Toggle Pages: 1
Letting a TextField loose Focus again (Read 714 times)
Letting a TextField loose Focus again
Jul 14th, 2009, 3:50pm
 
Hi everyone!
I'm currently writing a program that creates objects upon keyboard input. The user should be able to change the apperance of these objects by typing into one or more TextFields and change variables like labels, size, colour etc...

I've created a TextField by:
Code:
TextField inputLine = new TextField("Blahblah", 15);
add(inputLine);

in the setup().

Initially, the Object creation works fine.
But once you write into the TextField the TextField will obviously get the focus and "keyPressed()" will not be called anymore.

So I'm wondering what I have to do, to return the focus to the initial status, after something has been written into the TextField.

I've tried calling
Code:
  inputLine.setFocusable(false);
 inputLine.setFocusable(true);

right after each other...  Roll Eyes
But while the TextField looses it's focus, it doesn't seem like the Programm regains it, because "keyPressed()" still doesn't work.


And by the way, is there an easy way to arrange the TextFields on the screen (and change their apperance)?
I wouldn't exactly be thrilled if I had to write my own TextField class for that...  Undecided


Anyways, thanks in advance!
Re: Letting a TextField loose Focus again
Reply #1 - Jul 14th, 2009, 10:38pm
 
There is no TextField in Processing...
So if you indicate which library you use, perhaps you will get a meaningful answer.
Re: Letting a TextField loose Focus again
Reply #2 - Jul 15th, 2009, 2:04am
 
I'm aware of that.
I didn't import any Library so I guess it's coming from Swing or AWT or whatever Java-TextField Processing automatically imports..
Re: Letting a TextField loose Focus again
Reply #3 - Jul 15th, 2009, 2:35am
 
Ah, so that's the AWT TextField!
I haven't guessed it because the FAQ says: "The main rule when using Java code: You cannot use most of the AWT or Swing (which is built on the AWT), because it will interfere with the graphics model. [...] Even if they appear to work, such sketches will usually break when you try to run on other operating systems or other versions of Java."
So I stay away from AWT.

If you still go this way (eg. if that's for your own use), you can try this.requestFocus() perhaps.
Re: Letting a TextField loose Focus again
Reply #4 - Jul 15th, 2009, 4:50am
 
Hmm... Well up until then it worked fine so far... oO


"this.requestFocus()" works! Thank you very much!

(Even tough already went ahead and wrote a TextField-class myself...  Embarrassed)
Page Index Toggle Pages: 1