This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Focussing a TextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focussing a TextField" Watch "Focussing a TextField" New topic
Author

Focussing a TextField

Help Me
Greenhorn

Joined: Feb 28, 2006
Posts: 7
Hi,

I've written an AWT Frame with text fields and buttons. On pressing the "Clear" button, I want the text fields to be cleared and the cursor should return to the first text field. I've done clearing the text fields. But how do I return the cursor to the first text field?

Here is my code so far:

Thanks & Regards,
Babu Rajendran
[ February 18, 2007: Message edited by: Babu Rajendran ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43970
    
  33
Morning . . .

Please use the "code" button before sumbitting code; it makes it easier to read.

I tried it and as you say the fields cleared.
Not sure about the cursor going back to field 1, but try requesting the focus to the TextField. Go through the TextField API and you should find a suitable method, requestFocus().

CR
Help Me
Greenhorn

Joined: Feb 28, 2006
Posts: 7
Hi Campbell,

Thanks a lot! As you've mentioned, I found the requestFocus() method in the Component class. I'm now able to bring the cursor back to the textfield.

Thanks,
Babu
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43970
    
  33
Only too pleased to help . . .
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Focussing a TextField
 
It's not a secret anymore!