I've added bindings to a JComponent
's input map, by modifying the map returned by jCompInstance.getInputMap()
.
The first time I hit a key which I've binded, it works fine. Somehow, thereafter, the InputMap
gets wiped. What I mean by this is jCompInstance.getInputMap().size()
returns 0
.
I apologise for not offering a minimalistic code example which reproduces the problem; attempts to reduce my huge program have been futile.
What might be going on here?
Is there a way for me to set a watchpoint (in Eclipse) of the JComponent
's internal InputMap
to investigate how this may be occurring?
Thanks in advance!
A failed attempt to reproduce the problem is frustrating, but always worthwhile: it implies that your essential approach to key bindings is likely sound, and a reference example will guide your search for the problem.
Recall that each component's UI delegate is responsible for establishing its key bindings. At a guess, you might check several related things:
Ensure that Swing GUI objects are constructed and manipulated only on the event dispatch thread in the desired order, as suggested here.
Verify correct use of UIManager.setLookAndFeel()
; in particular, don't use it as a substitute for validate()
.
In a custom component, override updateUI()
to apply any custom bindings, as shown here for colors.