Listing the Actions in a Component : Actions « Swing JFC « Java






Listing the Actions in a Component

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

public class Main {
  public static void main(String[] argv) throws Exception {
    JButton component = new JButton("button");
    ActionMap map = component.getActionMap();
    list(map, map.keys());
    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]);
    }
  }
}

   
    
    
  








Related examples in the same category

1.Action DemoAction Demo
2.Creating an Action
3.Enabling an Action
4.UseActions: MenuUseActions: Menu
5.Action events are fired by subclasses of AbstractButton and includes buttons, checkboxes, and menus.
6.Sharing an InputMap or an ActionMap Between Two Components
7.Apply special filter to a JTextField
8.Listing the Key Bindings in a Component
9.A text component has an action map with actions and keymaps with actions
10.extends AbstractAction to create your won actionextends AbstractAction to create your won action