user186120
user186120

Reputation:

KeyboardFocusManager.setCurrentKeyboardFocusManager() breaks focus

I overrode DefaultKeyboardFocusManager to provide some special behavior for the Alt key. However, after setting this, I notice that hitting Tab on some of my text fields does not work.

I also experimented with even calling the following on the AWT, but this still exhibited the broken Tab behavior:

KeyboardFocusManager.setCurrentKeyboardFocusManager(new DefaultKeyboardFocusManager());

Why would setting the current keyboard focus manager have such bad effects?

Upvotes: 1

Views: 1055

Answers (2)

davesw
davesw

Reputation: 1850

I just ran into this problem as well. While developing a custom KeyboardFocusManager I noticed that even calling:

KeyboardFocusManager.setCurrentKeyboardFocusManager(new DefaultKeyboardFocusManager());

would change the behavior.

It appears that some early initialization was taking place, and the fix in my case was to set the KeyboardFocusManager before I showed any UI resources. I did this at the top of my application's main() function, and then the KeyboardFocusMangers worked as expected (both the default and my custom one).

Upvotes: 2

camickr
camickr

Reputation: 324207

You wrote some custom code and now you have problems? Just a guess here but maybe the problem is with your code?

If you need more help post your SSCCE.

Upvotes: 0

Related Questions