Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus problems in an interior JTextField

 
Anne Forumer
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic