码迷,mamicode.com
首页 > 其他好文 > 详细

e858. 将键盘键和事件绑定

时间:2018-09-06 10:59:38      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:focus   sam   pre   ase   component   NPU   number   released   span   

This example creates a number of keystrokes and adds them to the input map of a component. When a keystroke is added to an input map, an action name must be supplied. This action is invoked when the keystroke is pressed while the component has the focus.

    // Create some keystrokes and bind them all to the same action
    component.getInputMap().put(KeyStroke.getKeyStroke("F2"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("control A"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("shift F2"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke(‘(‘), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("button3 F"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("typed x"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("released DELETE"), "actionName");
    component.getInputMap().put(KeyStroke.getKeyStroke("shift UP"), "actionName");
    
    // Add the action to the component
    component.getActionMap().put("actionName",
        new AbstractAction("actionName") {
            public void actionPerformed(ActionEvent evt) {
                process(evt);
            }
        }
    );

 

Related Examples

e858. 将键盘键和事件绑定

标签:focus   sam   pre   ase   component   NPU   number   released   span   

原文地址:https://www.cnblogs.com/borter/p/9596117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!