what i want is
when my textfield is not in focus , by pressing alt+I my textField should get focus
one long way to do this is
i need to register focus listener on all my components , ie menu items , tool bars, etc so that when any of them is in focus and user press this alt+I textField should receive focus
do any one has any other way to do the same ?
The JComponent class supports key bindings as a way of responding to individual keys typed by a user. Here are some examples of when key bindings are appropriate:
You're creating a custom component and want to support keyboard access to it.
For example, you might want the component to react when it has the "focus" and the user presses the Space key.
but my textfield doesn't have focus so what then ?
It sets the key accelerator that will cause the receiving text component to get the focus. The accelerator will be the key combination of the alt key and the character given (converted to upper case). By default, there is no focus accelerator key. Any previous key accelerator setting will be superseded. A '\0' key setting will be registered, and has the effect of turning off the focus accelerator. When the new key is set, a PropertyChange event (FOCUS_ACCELERATOR_KEY) will be fired.
Joined: Jun 09, 2003
> but my textfield doesn't have focus so what then ?
you needed to read further down the page
The component's window either has the focus or contains the component that has the focus. This input map is commonly used for mnemonics or accelerators, which need to be active regardless of where focus is in the window.
Joined: Jun 13, 2009
I like to use label / text field pairs for this. Something like:
Behind the scens the Key Bindings will be created automatically for you and you have a self documenting interface where Alt-F can be used to set focus on the text field.