Java Swing ActionMap list action

Description

Java Swing ActionMap list action

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());//  w  ww. j  a  va2s  . c  o m
    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