Java JComponent list action map

Description

Java JComponent list action map

import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.JButton;
import javax.swing.JComponent;

public class Main {
  public static void main(String[] argv) throws Exception {
    JComponent component = new JButton("button");
    ActionMap map = component.getActionMap();
    list(map, map.keys());/*from  w w  w . j  a va2s .c  om*/
    list(map, map.allKeys());
  }

  static void list(ActionMap map, Object[] actionKeys) {
    if (actionKeys == null) {
      return;
    }
    for (int i = 0; i < actionKeys.length; i++) {
      // Get the action bound to this action key
      while (map.get(actionKeys[i]) == null) {
        map = map.getParent();
      }
      Action action = (Action) map.get(actionKeys[i]);
      System.out.println(action.getValue(Action.NAME));
    }
  }
}



PreviousNext

Related