This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Ho could I erase the text field contents as soon as the user presses the CTRL key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ho could I erase the text field contents as soon as the user presses the CTRL key" Watch "Ho could I erase the text field contents as soon as the user presses the CTRL key" New topic
Author

Ho could I erase the text field contents as soon as the user presses the CTRL key

kei hosima
Greenhorn

Joined: Feb 23, 2003
Posts: 13
Hello.
I hope someone could help me.
How could I erase a text field's contents as soon as the user presses the CTRL key while the text field has focus?
"data" is a properly instantiated TextField object with class-wide scope and the current object as its registered KeyListener.
public void keyTyped (KeyEvent e) {
TextField t = data.getText();
t.clearRect (0, 0, data.getWidth(), data.getHeight());
}
the above code won't work.
I would really appreciate your help.
Thanks in advance.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi kei,
Try something like this:


Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
kei hosima
Greenhorn

Joined: Feb 23, 2003
Posts: 13
Michael
Thank you so much for your help.
I'll try your code.
thank you!
kei
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ho could I erase the text field contents as soon as the user presses the CTRL key
 
Similar Threads
sun solaris , copy keyboard button
How to change the name of root in JTree at my will
How to issue command in Java program
Tab Key Binding JTextField
Stop Textfield from Going Blank