树。空格键热键

时间:2012-02-21 18:03:38

标签: java listener vaadin

我想使用空格键热键来展开/折叠节点。它非常适合输入,它不适用于空间(只需选择/取消选择节点)。这是我的代码:

 final Action actionEnter = new ShortcutAction("Select node",
            ShortcutAction.KeyCode.ENTER, null);
    final Action actionSpace = new ShortcutAction("Select node1",
            ShortcutAction.KeyCode.SPACEBAR, null);

    treePanel.addActionHandler(new Action.Handler() {

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            if (action==actionEnter || action==actionSpace){
                Object curId = tree.getValue();
                expandCollapse(curId);
            }
        }

        @Override
        public Action[] getActions(Object target, Object sender) {
            return new Action[] { actionEnter, actionSpace };
        }
    });

太空热键有什么问题?

1 个答案:

答案 0 :(得分:0)

向树中添加KeyListener,然后您就可以处理所有事件。