Reputation: 2515
I need to keep keyboard input focus on a single component inside a JPanel. It's for an application with a on-screen-keyboard.
Upvotes: 0
Views: 3999
Reputation: 13728
This will give you focus on your singleComponent when opening your Frame, without having to change the focus policy of enything else: singleComponent.requestFocusInWindow();
Since the focus will not freeze, you will need to setFocusable(false) for the other components like camicr suggests.
Upvotes: 0
Reputation: 11952
You better put the focus back to the component (component.grabFocus()
) after pressing a button on the on-screen keyboard.
Or you could set focus listener (component.addFocusListener(FocusListener l)
) and never let go of the focus by calling grabFocus() in the focusLost()
method of FocusListener
.
Upvotes: 1
Reputation: 324197
Not sure I really understand the question. But you can try something like:
otherComponents.setFocusable( false );
You also might need to use a custom FocusTraversalPolicy.
If you need more help then post a SSCCE that demonstrates the problem.
Upvotes: 1