Mega Code Archive

 
Categories / Java / Swing JFC
 

Listing the Key Bindings in a JTextComponent Keymap

import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import javax.swing.Action; import javax.swing.JTextArea; import javax.swing.KeyStroke; import javax.swing.text.Keymap; public class Main {   public static void main(String[] argv) throws Exception {     JTextArea component = new JTextArea();     Keymap map = component.getKeymap();     while (map != null) {       KeyStroke[] keys = map.getBoundKeyStrokes();       for (int i = 0; i < keys.length; i++) {         System.out.println(keys[i].getKeyChar());                 Action action = (Action) map.getAction(keys[i]);         System.out.println(action);       }       Action defAction = map.getDefaultAction();       System.out.println(defAction);       map = map.getResolveParent();     }   } }