aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
Consider Paul's rocket mass heater.
 
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
Stop Textfield from Going Blank
How to issue command in Java program
How to change the name of root in JTree at my will
Tab Key Binding JTextField