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. 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-1导入JavaScript插件

    导入JavaScript插件 Bootstrap除了包含丰富的Web组件之外,如前面介绍的下拉菜单.按钮组.导航.分页等.他还包括一些JavaScript的插件. Bootstrap的JavaScri ...

  2. MOTIONEVENT的GETX()和GETRAWX()和VIEW的GETLEFT()3个方法的区别

  3. WebService中方法的重载

    阅读目录 一:WebService中的方法是否允许重载? 二:为什么WebService中不支持方法的重载? 三:如何解决WebService中方法的重载? 一:WebService中的方法是否允许重 ...

  4. Lintcode: Interleaving Positive and Negative Numbers 解题报告

    Interleaving Positive and Negative Numbers 原题链接 : http://lintcode.com/zh-cn/problem/interleaving-pos ...

  5. shell数组应用

    引言 在Linux平台上工作,我们经常需要使用shell来编写一些有用.有意义的脚本程序.有时,会经常使用shell数组.那么,shell中的数组是怎么表现的呢,又是怎么定义的呢?接下来逐一的进行讲解 ...

  6. JAVA-JSP内置对象之page对象调用Servlet

    相关资料:<21天学通Java Web开发> page对象1.page对象代表JSP转译后的Servlet.2.通过page对象可以非常方便地调用Servlet类中定义的方法. pageD ...

  7. pandas 常用函数整理

    pandas常用函数整理,作为个人笔记. 仅标记函数大概用途做索引用,具体使用方式请参照pandas官方技术文档. 约定 from pandas import Series, DataFrame im ...

  8. java程序设计

    IP地址计数器 原理:获取用户的IP地址,然后存入数据库,当再次访问时查询数据库是否存在该条数据,即可完成此程序 设计过程 创建一个连接数据库类:DB.java package com.count.O ...

  9. Android 程序drawable资源保存到data目录

    今天做了个小功能,就是把我们程序Drawable里面的图片保存到data目录下面,然后另外一个程序需要读取data目录里面保存的图片.涉及了data目录读写.这功能看上去挺简单,不过实际做的时候还是遇 ...

  10. Java 1.7 ThreadPoolExecutor源代码解析

    相比1.6,1.7有些变化: 1.        添加了一个TIDYING状态.这个状态是介于STOP和TERMINATED之间的.假设运行完terminated钩子函数后状态就变成TERMINATE ...