Always focus on JFrame

1

I need when I click on any button in my application the focus will return to JFrame . Is there any method for this?

I could call the MeuFrame.requestFocus() method on every ActionPerformed , but this would take a long time.

    
asked by anonymous 13.07.2015 / 20:24

1 answer

1

There is, try:

You say to your jButton transfer the focus and ask your jFrame to request that focus.

 jButton.transferFocus();
 jFrame.requestFocus();

You can still get focus by forcing through:

jFrame.grabFocus();

This method gets focus regardless of who has it (it forces the focus to be transferred to you), even bringing focus to the window if it is not active.

I would recommend using it the first way, because the effect of the second may be unwanted to the user.

    
13.07.2015 / 20:28