Yoda
Yoda

Reputation: 18068

How to make JTextField lose its focus?

Exacly as stated in the subject how to make JTextField lose its focus?

Something like:

jtf.setFocus(false)

Upvotes: 1

Views: 8139

Answers (4)

peq
peq

Reputation: 329

If you don't want to transfer the focus use this:

KeyboardFocusManager.getCurrentKeyboardFocusManager().clearFocusOwner();

Upvotes: 1

HALO
HALO

Reputation: 11

One can also focus on a panel so that it would look like no components were focused

jpanel1.requestFocusInWindow();

Upvotes: 0

Reimeus
Reimeus

Reputation: 159774

You could simply transfer focus to another component:

myOtherComponent.requestFocusInWindow();

Upvotes: 7

Usman Salihin
Usman Salihin

Reputation: 281

You may call requestFocus() method from another control

Upvotes: 0

Related Questions