Search code examples
javaswingfocus

How do you set a focus on JTextField in Swing?


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


Solution

  • Would Component.requestFocus() give you what you need?