Java: Swing: Components: Menus: Key handling
Method/Class | MenuElement.processKeyEvent | standard key event processing changes |
|---|---|---|
JMenuBar | empty (usually never called as it is the root) | processKeyBinding (for all conditions) forwards to all MenuElement descendants special key handling (KeyboardManager)? |
JPopupMenu | empty | processKeyEvent first* forwards to MenuSelectionManager; only super if not consumed |
JMenu | (inherited from JMenuItem) | processKeyEvent first* forwards to MenuSelectionManager; only super if not consumed |
JMenuItem | fires menu key event -> LAF |
* This gives these keys absolute priority (before KeyListeners, input map key strokes)
JMenuBar/JPopupMenu seem to assume never to get the focus.
Does JMenuItem not get the focus? No (OTOH, it has explicit code to repaint on focus lost).
BasicPopupMenuUI forwards KeyEvents from the root pane (when that "happens" to get the focus) to the menu selection manager.
rather straightforward): loop backwards over selected path, event is sent to the showing components of the iteration's current element's sub elements; stop as soon as event is consumed
The root of the selected path will not be sent the event.
(this has protection against the selected path being changed meanwhile; it probably shouldn't unless the event *is* consumed and then it will stop anyway). As the desired path is passed, there is no need for the MenuElement to guess.
If a menu element's component is not "related" to the selected path, then it probably should not have the focus ...
JMenuBar: forwarding of KeyStroke (shouldn't instead JMenu pass the events also to its popup menu?)
BasicMenuBarUI: take focus action: sets selected path to [ menu bar, first menu, its popup menu ]
BasicMenuItemUI: accelerator when in focused window (calls doClick)
BasicMenuUI: shortcut stuff???
old: BasicMenuItemUI: typed for mnemonic (->doClick). BasicMenuUI: typed changes selected path directly (appends popup menu, first sub element).
SynthMenu/ItemUI copied
(C) 2001-2009 Christian Kaufhold (swing@chka.de)