So you are trying to have a short cut key associated with a component that is not in the window of focus, is that what you are stating here?
Let me explain ........
lets say we have got 3 textboxes and 2 button on a jframe. Now, i want to add a shortcut to one of the buttons such that it should work when the focus is on either of the 3 textboxes or the 2 buttons or even the frame itself.
I think now you will understand what i want......
When I stated that i tried all the overloaded methods and all its combinations, it should have been cleared then itself.
Finally you've actually stated that you tried "JComponent.WHEN_IN_FOCUSED_WINDOW".
Maybe, you are right here. I cannot test this.
The Key Bindings do work. The problem is that when focus is on a "text field", it also has a Key Binding for "Control X", which is to do a "cut" of any selected text. The Key Binding for the component with focus takes precedence over the other general bindings.
I tabbed to calculate and VOILA !!! --- It DIDN'T work ---
Tab to the Calculate button and the Control X will work.
It only works when the button on which the inputmap is configured has the focus.
Thanks for the suggestion. I tried that (CTRL+D and CTRL+J) also and again the same problem.
So the solution to your problem is to choose another Key Binding to use.
I don't want to specifically apply that to EXIT button. I can apply it to Calculate button if it works or any button in the future once I get it to work.
I can't find any example of a Windows program that actually sets an accelerator to close an application. By default you can just close the window using Alt-F4 if you want an accelerator.