Normally, a keystroke registered to a component is activated when the component has the focus. This type of activation condition is called WHEN_FOCUSED. It is possible to specify that a keystroke be activated if any component (including itself) in the window has the focus. This type of keystroke activation condition is called WHEN_IN_FOCUSED_WINDOW.

Keyboard accelerators use this type of keystroke activation condition. For example, in many applications, regardless of which component has the focus, typing F1 in an active window causes a help window to appear.

There are three types of activation conditions available: WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, and WHEN_IN_FOCUSED_WINDOW. When a key is typed, the focused component is checked for a registered keystroke to handle the typed key. If found, the action bound to the keystroke is invoked. If not found, the set of WHEN_ANCESTOR_OF_FOCUSED_COMPONENT keystrokes is searched for a handler of the typed key. WHEN_ANCESTOR_OF_FOCUSED_COMPONENT is described in e621 Activating a Keystroke When Any Child Component Has Focus. If none are found still, the set of WHEN_IN_FOCUSED_WINDOW keystrokes is searched for a handler of the typed key.

In non-WHEN_FOCUSED activated keystrokes, the source of the resulting action event is the component to which the keystroke is registered, not the focused component.

    // To create an action, see e855 创建一个事件

    // Register keystroke
component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke("F2"), action.getValue(Action.NAME)); // Register action
component.getActionMap().put(action.getValue(Action.NAME), action);
Related Examples

e620. Activating a Keystroke When Any Component in the Window Has Focus的更多相关文章

  1. e621. Activating a Keystroke When Any Child Component Has Focus

    Normally, a keystroke registered on a component is activated when the component has the focus. This ...

  2. e614. Setting the Initial Focused Component in a Window

    There is no straightforward way to set the initial focused component in a window. The typical method ...

  3. e610. Setting Focus Traversal Keys in a Component

    When the focus is on a component, any focus traversal keys set for that component override the defau ...

  4. How a non-windowed component can receive messages from Windows -- AllocateHWnd

    http://www.delphidabbler.com/articles?article=1 Why do it? Sometimes we need a non-windowed componen ...

  5. How a non-windowed component can receive messages from Windows

    Why do it? Sometimes we need a non-windowed component (i.e. one that isn't derived fromTWinControl) ...

  6. windows消息机制详解(转载)

    消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...

  7. e858. 将键盘键和事件绑定

    This example creates a number of keystrokes and adds them to the input map of a component. When a ke ...

  8. Scrapy爬虫入门系列3 将抓取到的数据存入数据库与验证数据有效性

    抓取到的item 会被发送到Item Pipeline进行处理 Item Pipeline常用于 cleansing HTML data validating scraped data (checki ...

  9. Android系统onKeyDown监控/拦截/监听/屏蔽返回键、菜单键和Home键

    在Android系统中用来显示界面的组件(Component)为Activity,也就是说只有重写Activity的onKeyDown方法来监控/拦截/屏蔽系统的返回键(back).菜单键(Menu) ...

随机推荐

  1. 每日英语:The Power of Parents Who Say 'No'

    I grew up in an affluent area. Most kids owned multiple Cabbage Patch dolls and Gear bags and pairs ...

  2. 关于CentOS 6下Hadoop占用系统态CPU高的处理办法【转】

    一次不经意发现Hadoop的系统态CPU使用率很高,然后百度一下居然是个已知问题. RHEL6优化了内存申请的效率,而且在某些场景下对KVM的性能有明显提升:http://www.Linux-kvm. ...

  3. nexus maven私服搭建

    1.在服务器上安装jdk 2.下载 nexus-3.14.0-04-unix.tar.gz,并上传到服务器/opt目录 3.解压 tar -zxvf nexus-3.14.0-04-unix.tar. ...

  4. ViewGroup

  5. JAVA-JSP内置对象之pageContext对象取得不同范围属性

    相关资料:<21天学通Java Web开发> pageContext对象取得不同范围属性 pageContextDemo.jsp <%@ page language="ja ...

  6. ubuntu 安装redis

    1. 下载安装: cd /tmp wget http://redis.googlecode.com/files/redis-2.2.4.tar.gz tar -zxf redis-2.2.4.tar. ...

  7. 【Unity笔记】寻路导航用NavMeshObstacle做动态阻挡

    通常情况下,静态的场景中,给场景物体静态标记中勾选Navigation Static后,在导航界面进行导航网格的烘培,可以得到一个静态的导航网格. 但是由于导航网格是静态烘焙好了的,游戏中动态生成的物 ...

  8. mybatis注解方式批量插入数据

    @Insert("<script>" + "INSERT INTO cms_portal_menu(name,service_type,index_code) ...

  9. Java log4j slf4j 日志配置笔记

    http://www.cnblogs.com/Scott007/p/3269018.html 日志的打印,在程序中是必不可少的,如果需要将不同的日志打印到不同的地方,则需要定义不同的Appender, ...

  10. JMeter (2) —— JMeter与WebDriver测试用户登陆以CAS SSO为例(101 Tutorial)

    JMeter (2) -- JMeter与WebDriver测试用户登陆以CAS SSO为例(101 Tutorial) 主要内容 JMeter与WebDriver测试用户登陆以CAS SSO为例 环 ...