How to set focus to JTextField
hi,
i have a class A which extends to JPanel
i have another class B which extends JFrame
in this class B(JFrame) i have added a JTabbedPane
To this JTabbedPane i have added JPanel (class A)
my problem is, in this Class A (JPanel) i have a JTextField
I want to have the default focus.
so can any one help me to set the focus to JTextField
thank you
# 2
You have a choice:
The simplest choice is to use textField.requestFocusInWindow(), as already suggested, straight after setVisible.
If your focusing issues are more complicated, you may want to look at java.awt.FocusTraversalPolicy.
You can define your own FocusTraversalPolicy, and set it using frame.setFocusTraversalPolicy(myNewPolicy).
You can read its API documentation, or ask for more help if needed.
Of course, if it's not that complex, stick with the first option!