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. Vue.js使用-组件(上篇)

    1.什么是组件 组件可以理解为定义的一个view模块,可重复使用. 2.组件使用 1)创建组件 var myComponent = Vue.extend({ template: ' this is a ...

  2. DIOCP开源项目-定义自己要发送的数据结构(MyObject)

    印象中网络程序都是sendBuffer和recvBuffer来发送数据和接收数据,本次Demo演示如何定义定义一个自己的对象,然后我们按照OO的思想直接进行对象的发送和接收,先上个流程图. 下面是客户 ...

  3. js模板引擎art-template使用方法

    art-template是款性能卓越的 js 模板引擎 https://aui.github.io/art-template/ 特性 拥有接近 JavaScript 渲染极限的的性能 调试友好:语法. ...

  4. JS中的history对象

    window.history指向History对象,它表示当前窗口的浏览历史. History对象保存了当前窗口访问过的所有页面网址. history.back()//后退到前一个网址 等同于 his ...

  5. 当滚动列表的时候,让input框失去焦点(移动端会收起键盘)

    1.拓展scroll.vue事件 beforeScroll:{ type:Boolean, default:false } if(this.beforeScroll){//滚动列表的时候收起键盘(移动 ...

  6. C#学习笔记(10)——再谈委托,不同国家问候的例子

    说明(2017-6-14 09:08:38): 1. 首先是一个简单的委托 (1)命名空间下定义一个委托MyDel: public delegate void MyDel(string name); ...

  7. vue前后分离动态路由和权限管理方案

    需求 需要根据不同的角色来显示不同的菜单 问题 系统是前后分离模式开发的,出现了后端接口和前端路由都需要权限管理. 思路 后端的接口肯定得验证权限 在前端做好组件名和组件的映射 前端的路由通过后端发回 ...

  8. <跟股市谚语学炒股> 读书笔记

    书在这里 一般情况下,当成交清单上显示的买盘金额大.笔数少,卖盘金额小.笔数多时,系主力在建仓.散户在卖出:相反,若买盘金额小.笔数多,卖盘金额大.笔数少时,系主力在出货.散户在买入 一般来说,当大盘 ...

  9. 采用dlopen、dlsym、dlclose dlopen dlerror加载动态链接库【总结】

    .前言 为了使程序方便扩展,具备通用性,可以采用插件形式.采用异步事件驱动模型,保证主程序逻辑不变,将各个业务已动态链接库的形式加载进来,这就是所谓的插件.linux提供了加载和处理动态链接库的系统调 ...

  10. PowerDesigner使用教程【转】

    PowerDesigner使用教程 —— 概念数据模型   一.概念数据模型概述    概念数据模型也称信息模型,它以实体-联系(Entity-RelationShip,简称E-R)理论为基础,并对这 ...