Reputation: 9959
As you can see, the passwordField is positioned before jButton1 in the navigator, however, when the usernameField is focused, and I press the TAB key, the second element being focused is the jButton1 and not the passwordField.
What really controls the order of focus?
Upvotes: 0
Views: 170
Reputation: 347184
The default focus transferral is based more on the visual layout the the order of the components. In this case it would want to go left to right, top to bottom. This is the expected behaviour – MadProgrammer just now edit
Take a look at How to use the Focus Subsystem, especially, Customizing Focus Traversal
Updated
Take a look at switching JTextFields by pressing Enter key, which demonstrates the use of a custom focus policy
Upvotes: 1
Reputation: 3141
Try to search tab index or tab order to set for the components
Upvotes: -1
Reputation: 7213
The phrase you need search for is "tab order": there is an answer to this here. Briefly, you will need to implement a FocusTraversalPolicy subclass, and make your container use it by calling setFocusTraversalPolicy.
Upvotes: 2