Normally, a keystroke registered to a component was activated when the component had the focus. This type of activation condition is called WHEN_FOCUSED
. It's possible to specify, a keystroke be activated if any component (including itself) in the window with the focus. This type of keystroke activation condition is called WHEN_IN_FOCUSED_WINDOW
.
Keyboard accelerators Use this type of keystroke activation condition. For example, in many applications, regardless of which component have the focus, typing F1 in an active window causes a Hel P window to appear.
There is three types of activation conditions available: WHEN_FOCUSED
, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
, and WHEN_IN_FOCUSED_WINDOW
. When a key is typed, the focused component are checked for a registered keystroke to handle the typed key. If found, the action bound to the keystroke is invoked. If not found, the set of WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
keystrokes are searched for a handler of the typed key. are WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
described in e621 Activating a keystroke when any child Component have Focus. If None is found still, the set of WHEN_IN_FOCUSED_WINDOW
keystrokes is searched for a handler of the typed key.
In non- WHEN_FOCUSED
activated keystrokes, the source of the resulting action event was the component to which the keystroke is Reg Istered, not the focused component.
e855 Create an event //Register keystroke component. Getinputmap (jcomponent.when_in_focused_ window). Put ( Keystroke.getkeystroke ("F2"action. GetValue (Action.name)); Register Action component. Getactionmap (). Put (action. GetValue (action.name), action);
e620. Activating a keystroke when all Component in the Window has Focus