e856. 列出一个组件的所有事件

Posted borter

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了e856. 列出一个组件的所有事件相关的知识,希望对你有一定的参考价值。

This example demonstrates how to list all the actions in a component.

    ActionMap map = component.getActionMap();
    
    // List actions in the component
    list(map, map.keys());
    
    // List actions in the component and in all parent action maps
    list(map, map.allKeys());
    
    public 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]);
        }
    }

A text component not only has an action map with actions, it also has keymaps with actions. Moreover, every keymap has a default action to handle any typed character key events not handled by any input map or keymap. The following code retrieves actions from these objects:

    // List the actions in the keymaps
    if (component instanceof JTextComponent) {
        JTextComponent textComp = (JTextComponent)component;
        Keymap keymap = textComp.getKeymap();
    
        while (keymap != null) {
            // Get actions in the keymap
            Action[] actions = keymap.getBoundActions();
            for (int i=0; i<actions.length; i++) {
                Action action = actions[i];
            }
    
            // Get the default action in the keymap
            Action defaultAction = keymap.getDefaultAction();
            keymap = keymap.getResolveParent();
        }
    }

 

Related Examples

以上是关于e856. 列出一个组件的所有事件的主要内容,如果未能解决你的问题,请参考以下文章

在每个用户的Rails中使用片段缓存

单击事件时,从 SQLite 自动刷新另一个选项卡

e860. 列出组件绑定的键盘键

微信小程序代码片段

如何在 javascript 中为所有事件添加事件侦听器而不单独列出它们?

如何根据Angular中一个组件中的click事件更改其他组件中的数据?