Java: Swing: Components: Key strokes
Keys are written in capital letters.All conditions are to be "and"ed, except where they are clearly meant separate. "(when) focused", "(when) ancestor of focused (component)", "(when) in focused window" are the "three" standard (JComponent) focus "conditions".
Keys | Function | Coded in | Implementation | Remarks | Workaround |
|---|---|---|---|---|---|
CTRL-F1 pressed | show tooltip of owner (focused) | ToolTipManager | installed (InputMap, ActionMap) on every registered component (unless no binding at all for focused - unreliable) | rudely overrides CTRL-F1 each time it is de/registered | Use special input map that ignores such KeyStrokes? |
ESCAPE pressed | hide tooltip of owner (focused) | ToolTipManager | installed on every registered component (unless no binding at all for focused - unreliable) | rudely overrides ESCAPE each time it is de/registered! | Use special input map that ignores such KeyStrokes? |
ENTER (pressed?) | fire action event | left to LAF, documented in JTextField | LAF registers KeyStroke, action provided by JTextField | n/a | |
ALT-focusAccelerator (pressed?) | request focus | left to LAF, documented in JTextComponent (historically (<1.3?) also implemented there) (focus action (first in JTextComponent, now in BasicTextUI is only enabled when editable, why?) | LAF BasicTextUI uses pressed (and UI input map) | don't use it (rather pointless anyway) | |
ESCAPE pressed | hide color chooser dialog (when in focused window) | JColorChooser | installed on internal button | standard LookAndFeels: for JFileChooser, JOptionPane by UI input map | n/a? |
TAB (any) | hide popup (focused) | JComboBox | processKeyEvent | probably a hack | n/a |
pressed; released; (typed and (ALT set implies CTRL set)) | valid for "key bindings" (input map) (all three conditions) | SwingUtilities | JComponent.processKeyBindings,SwingUtilities | weird: special handling of ALT at this level (or does it have nothing to do with ALT being used for mnemonics in the standard LAFs?) | n/a |
pressed, not SHIFT, CTRL, ALT, "accepted" by editor (possible more) | start editing, forward to editor (when focused) | JTable | processKeyBindings | does not consume if editor doesn't (although editing was started) | override it |
no control character (>=31, not 127), ALT set = CTRL set (typed, really from ActionEvent) | insert character (really action command) | DefaultEditorKit.DefaultKeyTypedAction | inserts if first character and modifier match criteria | Change Keymap or ActionMap? | |
CTRL-TAB pressed; SHIFT-CTRL-TAB pressed | managingFocus traversal keys (when focused, inherited) | JComponent | set in constructor (isManagingFocus) | set explicitly | |
CTRL-SHIFT-F1 pressed | dump container hierarchy to System.out (pre-process, doesn't consume) | Window | every Window | none | |
TAB pressed; CTRL-TAB pressed; SHIFT-TAB pressed; CTRL-SHIFT-TAB pressed (can be replaced by AWT property) | default focus traversal keys (when focused, inherited) | KeyboardFocusManager | indirectly by getDefaultFocusTraversalKeys | set explicitly | |
typed with Toolkit.menuShortcutKeyMask | used to determine whether forward events to menus (menu item/shortcut only distinguishes shift -not shift) (post-process, does consume) | MenuBar | every Frame with menu bar | n/a |
This is to show where such information is scattered. All other key information is read from/stored into the UIDefaults (by whatever mechanism)
(still dependence on which focus conditions are used in each UI class).
Keys | Function | Coded in | Implementation | Remarks |
|---|---|---|---|---|
pressed, no CTRL,ALT,META set, not UP, DOWN | type ahead key for selectWithKeyChar (when focused) | BasicComboBoxUI | KeyListener | |
typed, no CTRL,ALT,META set | type ahead key for getNextMatch (when focused) | BasicListUI, BasicTreeUI | KeyListener | |
ALT-mnemonic pressed/released; mnemonic released | obvious (when in focused window) | BasicButtonListener | set on button (UI) | Mode problem |
ALT-displayedMnemonic pressed/released | request focus on componentFor (when in focused window) | BasicLabelUI | pressed set on label (UI), released only while key pressed (dangerous) | Mode problem |
any of "Menu.shortcutKeys" -mnemonic pressed | obvious (when in focused window) | BasicMenuUI | set on menu item (UI) | |
mnemonic pressed/typed | obvious | BasicMenuItemUI BasicMenuUI | MenuKeyListener | |
ALT-mnemonic pressed | obvious (when ancestor of focused!) | BasicTabbedPaneUI | set on tabbedPane (UI) | |
TAB pressed; SHIFT-TAB pressed | focus traversal keys | BasicSplitPaneUI | set on splitPane | |
TAB pressed; SHIFT-TAB pressed | not focus traversal keys iff the text component is editable | BasicTextUI | set/removed on text component | |
ALT-pressed | show mnemonic (when in focused window) | WindowsRootPaneUI | set on root pane (UI) | |
ALT-pressed; ALT-released | ? always | WindowsPopupMenuUI | global? | |
ALT | assumed to be the modifier for mnemonics of menu items | MetalToolTipUI | for displayed accelerator string | |
ENTER (probably; any) | hack to forward the key stroke to JRootPane (should do with Action.isEnabled), where it is supposed to be the default button key (when ancestor of focused) | BasicComboBoxUI | in Action | |
ESCAPE (any) | ?, always | MetalFileChooserUI WindowsFileChooserUI | forwarded from JTable to file chooser if not editing (workaround?) |
(C) 2001-2009 Christian Kaufhold (swing@chka.de)