File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes How can a TextField get focus? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can a TextField get focus?" Watch "How can a TextField get focus?" New topic

How can a TextField get focus?

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
How can I let a text field get focus on it whenever it display?
How can I let this text field add a key strok ActionListener (Enter key) that mean when I type "Enter" key in this text field and some action will happen?
Please teach me. Thanks!
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
to get the focus to the textfield. use textfield.requestFocus();
and to respond to the enter key
- add keyListener to ur text field.
- in the keyReleased() method of ur key listener. just check
///enter key pressed do ......
///do nothing

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi deekasha gunwant:
Thank you very much! Moreover do you know How can I determine a database is empty or not, if it is not empty, how can I print out the names of all the tables currently existing in the database.
Thank you for your teach!
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
u can quey the database by querying the system table "tabs" (i'm taking wrt Oracle) if result set is null then u can say that database was empty, and far as the problem of displaying column name is concerned u can query the same tabe for table_name column and display the result in either text area or table or whatever u wan't to use. but u see it depends a lot on the database u r using. i have written it wrt Oracle only. i don't know whether it will be helpful for u or not.
Naima Muzammal
I agree. Here's the link:
subject: How can a TextField get focus?
Similar Threads
first keyUP element in field
accepting only numbers in a text field
Submitting a form on pressing Enter key
"enter key" button focus ?
Is onchange="submit()" will cause the loosing focus from current inputText field ?