File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Focus problems in an interior JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus problems in an interior JTextField" Watch "Focus problems in an interior JTextField" New topic
Author

Focus problems in an interior JTextField

Anne Forumer
Ranch Hand

Joined: Apr 19, 2004
Posts: 72
JDK1.3:

I have a JTextField, F1, inside a JComponent C1. C1 is inside another JComponent C2. C2 is one of the panes in a JTabbedPane. JTabbedPane is in an Applet.

I am unable to have the focus come up in F1 when Applet shows. I have tried a requestFocus() inside componentShown() in C1, but apparently this is never called.

C1 also has a method which clears all fields before the applet shows. requestFocus() in this method doesn't help either!

I'd appreciate any suggestions on how to have the applet come up with the focus in F1.

Thanks
KR Campbell
Ranch Hand

Joined: Mar 26, 2004
Posts: 124
The KeyboardFocusManager is responsible for handling this.

KeyboardFocusManager.getCurrentKeyboardFocusManager() will return the correct instance. Try playing with this and the FocusTraversalPolicy which determines which the next, previous, initial and first components are.

You should be able to use these to figure out the order and roots of your components and if need be force selection of the component you want.

HTH
Regards,
Ken
 
jQuery in Action, 2nd edition
 
subject: Focus problems in an interior JTextField
 
Similar Threads
ENTER KEY with JComboBox
Setting hot keys
How to stop JTextField collapsing when using GridBagLayout?
Garbage collection doubt
JcomboBox