e620. Activating a Keystroke When Any Component in the Window Has Focus
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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) ...
- windows消息机制详解(转载)
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...
- e858. 将键盘键和事件绑定
This example creates a number of keystrokes and adds them to the input map of a component. When a ke ...
- Scrapy爬虫入门系列3 将抓取到的数据存入数据库与验证数据有效性
抓取到的item 会被发送到Item Pipeline进行处理 Item Pipeline常用于 cleansing HTML data validating scraped data (checki ...
- Android系统onKeyDown监控/拦截/监听/屏蔽返回键、菜单键和Home键
在Android系统中用来显示界面的组件(Component)为Activity,也就是说只有重写Activity的onKeyDown方法来监控/拦截/屏蔽系统的返回键(back).菜单键(Menu) ...
随机推荐
- 【工具】我的Eclipse使用习惯
查看代码结构 查看类的层级结构,可用选中类名,按F4,可查看: 类的层级结构: 类的上级结构: 类的下级结构: 安装反编译工具Eclipse Class Decompiler 在Eclipse Mar ...
- String.format和MessageFormat.format的对比用法
1.MessageFormat.format import java.text.MessageFormat; /** * Created by SYJ on 2017/9/13. */ public ...
- ubuntu 解压命令
ubuntu解压命令.tar解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)———————————————. ...
- Android下基于SDL的位图渲染(二)理论篇
理论篇 上一篇中介绍了如何将SDL2源码应用到Android渲染中,实际上SDL本身提供的android-project实现了基于android的c运行时环境,通过上面实践篇的介绍,就是完成这个环境搭 ...
- IE 此网站的某个加载项无法运行
1.使用IE浏览器 发生问题,一直以为是浏览器安全设置出问题,将IE安全级别调到最低,还是同样的问题 2.转用360浏览器(IE内核) 问题一样,提示略有不同 点击需要运行的java程序 解决方法 1 ...
- java 多线程 26 : 线程池
使用线程池与不使用线程池的差别 先来看一下使用线程池与不适应线程池的差别,第一段代码是使用线程池的: public static void main(String[] args) { long sta ...
- sscanf函数——强大的C语言库函数
这个函数真的很强大,这篇随笔也将一直更新一些总结,直到涵盖大多数应用: eg1: 今天公司项目中从云端获取了一段字符串---"+CBC: 0,90,4090" 我想获取其中的数字0 ...
- 设置模式之单例模式(附上一个Objective-C编写的播放音乐的单例类)
在查阅Cocoa Touch开发文档时,会发现框架中随处可见的大量单例类,比如说,UIApplication.NSFileManager 等. UIApplication 框架中极为常用的一个单例类, ...
- JAVA-JSP内置对象之out对象
相关资料:<21天学通Java Web开发> out对象1.out对象用来向网页输出信息. 方法 返回值 方法说 ...
- java基础篇---反射机制
一.JAVA是动态语言吗? 一般而言,说到动态言,都是指在程序运行时允许改变程序结构或者变量类型,从这个观点看,JAVA和C++一样,都不是动态语言. 但JAVA它却有着一个非常突出的动态相关机制:反 ...