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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 5.7 Components — Sending Actions From Components to Your Application

    一.概述 1. 当一个组件在模板中被使用时,它具有发送action到这个模板的controller和routes的能力.当重大事件发生的时候,这些允许组件通知application,比如点击组件一个特 ...

  4. 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 ...

  5. ExtJS笔记5 Components

    参考 :http://blog.csdn.net/zhangxin09/article/details/6914882 An Ext JS application's UI is made up of ...

  6. Android ANR Waiting because no window has focus问题分析

    转自:https://www.cnblogs.com/MMLoveMeMM/articles/4849667.html 这种问题主要是发生在两个应用页面之间切换的时候,这个临界点的时候,一个页面正在起 ...

  7. 5、二、App Components(应用程序组件):0、概述

    二.App Components(应用程序组件) 0.概述   App Components Android's application framework lets you create rich ...

  8. 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 ...

  9. [Vue] Load components when needed with Vue async components

    In large applications, dividing the application into smaller chunks is often times necessary. In thi ...

随机推荐

  1. angular的uiRouter服务学习(1)

    angular有内置的路由服务$route:angular -- $route API翻译 使用$route可以帮助实现路由的切换,视图的改变,但是这个内置的$route只包含了基本的功能,在很多场合 ...

  2. 谷歌Chrome浏览器小于12px字号显示的BUG

    webkit的私有属性:html{-webkit-text-size-adjust:none;}

  3. String.format和MessageFormat.format的对比用法

    1.MessageFormat.format import java.text.MessageFormat; /** * Created by SYJ on 2017/9/13. */ public ...

  4. Context.startActivity出现AndroidRuntimeException

    转:http://hi.baidu.com/huaxinchang/item/e1a771cf4d424312b77a2416 昨天做了一个Activity的启动动画,效果是点击桌面图标先出现动画后启 ...

  5. RestTemplate 发送 get 请求使用误区 多值为null

    http://blog.csdn.net/zhousenshan/article/details/71055687 ****************************************** ...

  6. spark编译报错信息简介

    spark编译需要环境 git java1.+ maven R 报错信息1: [INFO] ------------------------------------------------------ ...

  7. MySQL数据库权限管理

    # MySQL数据库权限管理 ### 前言------------------------------ 对不同的用户赋予不同级别的访问权限是个好习惯- 杜绝一些恶意用户 ### 参考资料------- ...

  8. Server.MapPath 出现未将对象引用设置到对象的实例

    此文仅在于使遇到相似问题的朋友能少走弯路 asp.net中我用一个页面的cs文件调用一个自定义类,这个自定义类再调用 System.Web.HttpContext.Current.Server.Map ...

  9. ARKit从入门到精通(5)-ARScnView介绍

    转载:http://blog.csdn.net/u013263917/article/details/73156918 AR视图,在第一小节笔者介绍过,ARKit支持3D的AR场景和2D的AR场景,A ...

  10. Cpu表现出正弦曲线

    #include <windows.h> #include <math.h> int main(void) { SetThreadAffinityMask(GetCurrent ...