e609. Listening to All Focus Changes Between Components in an Application
To listen to focus change events between components, install a listener with the keyboard focus manager. If you need the ability to veto (reject) a focus change, install a vetoable listener with the keyboard focus manager.
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener(new FocusChangeListener());
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addVetoableChangeListener(new FocusVetoableChangeListener()); class FocusChangeListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent evt) {
Component oldComp = (Component)evt.getOldValue();
Component newComp = (Component)evt.getNewValue(); if ("focusOwner".equals(evt.getPropertyName())) {
if (oldComp == null) {
// the newComp component gained the focus
} else {
// the oldComp component lost the focus
}
} else if ("focusedWindow".equals(evt.getPropertyName())) {
if (oldComp == null) {
// the newComp window gained the focus
} else {
// the oldComp window lost the focus
}
}
}
} class FocusVetoableChangeListener implements VetoableChangeListener {
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
Component oldComp = (Component)evt.getOldValue();
Component newComp = (Component)evt.getNewValue(); if ("focusOwner".equals(evt.getPropertyName())) {
if (oldComp == null) {
// the newComp component will gain the focus
} else {
// the oldComp component will lose the focus
}
} else if ("focusedWindow".equals(evt.getPropertyName())) {
if (oldComp == null) {
// the newComp window will gain the focus
} else {
// the oldComp window will lose the focus
}
} boolean vetoFocusChange = false;
if (vetoFocusChange) {
throw new PropertyVetoException("message", evt);
}
}
| Related Examples | 
e609. Listening to All Focus Changes Between Components in an Application的更多相关文章
- e611. Setting Focus Traversal Keys for the Entire Application
		
This example changes the focus traversal keys for the entire application. For an example of how to c ...
 - ssemble JavaBeans components into an application without having to write any code
		
https://docs.oracle.com/javase/tutorial/javabeans/ https://docs.oracle.com/javase/tutorial/javabeans ...
 - 5.7 Components — Sending Actions From Components to Your Application
		
一.概述 1. 当一个组件在模板中被使用时,它具有发送action到这个模板的controller和routes的能力.当重大事件发生的时候,这些允许组件通知application,比如点击组件一个特 ...
 - e606. Determining Which Component or Window Has the Focus
		
// null is returned if none of the components in this application has the focus Component compFocusO ...
 - ExtJS笔记5 Components
		
参考 :http://blog.csdn.net/zhangxin09/article/details/6914882 An Ext JS application's UI is made up of ...
 - Android ANR Waiting because no window has focus问题分析
		
转自:https://www.cnblogs.com/MMLoveMeMM/articles/4849667.html 这种问题主要是发生在两个应用页面之间切换的时候,这个临界点的时候,一个页面正在起 ...
 - 5、二、App Components(应用程序组件):0、概述
		
二.App Components(应用程序组件) 0.概述 App Components Android's application framework lets you create rich ...
 - 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 ...
 - [Vue] Load components when needed with Vue async components
		
In large applications, dividing the application into smaller chunks is often times necessary. In thi ...
 
随机推荐
- Tornado中gen.coroutine详解
			
1.gen.coroutine的作用 自动执行生成器 2.Future对象 在介绍异步使用之前,先了解一下Future对象的作用. Future简单可以理解为一个占位符,将来会执行的对象,类似java ...
 - [转] lua 获取本地当月天数
			
亲测,无误. 原文传送门:lua 获取本地当月天数 开发中有用到,记录一下. local year,month = os.date("%Y", os.time()), os.dat ...
 - ListView数据更新后,自动滚动到底部(聊天时常用)| Listview Scroll to the end of the list after updating the list
			
转:http://www.cnblogs.com/bjshsqlt/p/3311830.html If you would like to after you have updated by list ...
 - 使用instantclient_11_2和pl/sql Developer连接oracle远程数据库
			
https://blog.csdn.net/itmyhome1990/article/details/8796781 ***************************************** ...
 - C# LINQ系列:LINQ to DataSet的DataTable操作  及 DataTable与Linq相互转换
			
LINQ to DataSet需要使用System.Core.dll.System.Data.dll和System.Data.DataSetExtensions.dll,在项目中添加引用System. ...
 - python 使用pillow将图片转换为webp格式
			
1.webp格式 webp格式是谷歌开发的一种旨在加快图片加载速度的格式,将图片转为webp格式后,体积约为原来的2/3,这可以节省大量的服务器带宽,微信公众号文章里的图片就是这种格式的. 2.使用p ...
 - Natural Language Processing, 2017, Mar.29, Weekly Report
			
Distributed Representations of Words and Phrases and their Compositionality T Mikolov, I Sutskever, ...
 - asp.net mvc之TempData、ViewData、ViewBag
			
★ViewData和ViewBag:生命周期相同,仅对当前View有效,不同的是ViewBag的类型不是字典的键值对结构,而是dynamic动态类型. ViewData ViewBag Key/Val ...
 - hystrix服务降级和服务熔断的区别
			
故事的背景是这样的:由于小强在工作中碰到一些问题,于是想请教一下业界大牛小壮.于是发生了下面的两个场景: 小强在拿起常用手机拨号时发现该手机没有能够拨通,所以就拿出了备用手机拨通了某A的电话,这个过程 ...
 - linux 正则表达式和通配符
			
linux 正则表达式和通配符 通配符用于查找文件 包含三种: * ? [] * 代表任意个任意字符 ? 代表任意一个字符 [] 代表中括号中的一个字符 正则表达式(正则是包含匹配,只要包含就可以匹 ...