![]() |
The Java Developers Almanac 1.4 |
|
e1005. Listing the Key Bindings in a JTextComponent KeymapA text component has an additional list of key bindings that is searched after its inputmaps. This additional list is called a keymap. The inputmap mechanism is newer but keymaps were left in place for backwards compatibility. JTextArea component = new JTextArea();
Keymap map = component.getKeymap();
while (map != null) {
KeyStroke[] keys = map.getBoundKeyStrokes();
for (int i=0; i<keys.length; i++) {
// This method is defined in e859 Converting a KeyStroke to a String
String keystrokeStr = keyStroke2String(keys[i]);
// Get the action name bound to this keystroke
Action action = (Action)map.getAction(keys[i]);
}
// The default action is invoked if a character is typed
// and no key binding exists in the component's InputMap or Keymap.
Action defAction = map.getDefaultAction();
// Process all parent keymaps as well
map = map.getResolveParent();
}
e1002. Creating a Custom Editing Command for a JTextComponent e1003. Overriding a Few Default Typed Key Bindings in a JTextComponent e1004. Overriding Many Default Typed Key Bindings in a JTextComponent
© 2002 Addison-Wesley. |