Reputation: 129433
I have a JComboBox
with an key listener.
When I hit <enter>
, I fire off some action, and then I need to to lose focus on the JComboBox
!
To focus on it, I can do JComboBoxObject.grabFocus();
But doing transferFocus()
to get the focus to a next element (I don't care WHERE the focus goes, just away from combo box) does NOT work.
Doing grabFocus()
from another combo box works, but seems like a pretty annoying hack to me. Is there a better solution?
Upvotes: 1
Views: 4056
Reputation: 483
I can suggest you to first use the
.getNextFocusableComponent()
and then use the
.requestFocusInWindow()
that means Implementing it like this,
JComboBox.getNextFocusableComponent().requestFocusInWindow();
One important note is that .getNextFocusableComponent() has become obsolete but it can work really better, you can use it but If you have any other solution, I would prefer not using this.
Upvotes: 3