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

[404 byte] By [Inspiron123a] at [2007-11-27 4:41:40]
# 1
Once the GUI is visible you do:textField.requestFocusInWindow();
camickra at 2007-7-12 9:53:06 > top of Java-index,Desktop,Core GUI APIs...
# 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!

clairec666a at 2007-7-12 9:53:06 > top of Java-index,Desktop,Core GUI APIs...
# 3
hai Thank you i can able to get focus using FocusTraversalPolicy.Thank you
Inspiron123a at 2007-7-12 9:53:06 > top of Java-index,Desktop,Core GUI APIs...