tags:

views:

376

answers:

2

Hello, I have created one form using Swing in Java.In the form I have used one textfield on which I have to set the focus whenever I press the key.How to set focus on a particular component in Java ?

+4  A: 

Hi there, Just a simple search through the API would give you Component.requestFocus(), is that what you need?

phunehehe
Thanks,let me see whether it works for me or not
om
Took me five minutes to find it ... so much for "simple" search :-( – ah well, the Java API docs aren't a paragon of clarity anyway :-)
Joey
A: 

Now that we've searched the API all we need to do is read the API.

According to the API documentation:

"Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible. "

camickr