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. javascript基础拾遗(十三)

    1.jQuery的特点 jQuery是目前非常流行的javascript库,理念是"Write Less,Do More" 1)消除浏览器差异 2)简洁的操作DOM方法 3)轻松实 ...

  2. ubuntu下安装与卸载软件方法

    http://www.cnblogs.com/JamyWong/archive/2009/11/19/1606442.html 1.通过deb包安装的情况:安装.deb包:代码:sudo dpkg - ...

  3. 【php】https请求

    /** * 模拟提交参数,支持https提交 可用于各类api请求 * @param string $url : 提交的地址 * @param array $data :POST数组 * @param ...

  4. shell数组应用

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

  5. maven 使用记录之修改 maven默认jdk版本

    maven package执行的时候会遇到jdk版本不对的问题 :原因是 maven所指定的jdk版本与项目使用的jdk版本不一致 1.项目属性的 java compiler可以设置 2.直接修改 m ...

  6. 备份Android机上的照片

    [本文出自天外归云的博客园] 一年一度的春节放假开始了,今天收拾柜子发现了一台上大学时候用的android机,里面有几百张当年的回忆. 写了个shell脚本遍历了下照片存放的路径,然后用一个pytho ...

  7. poj1988(判断一个结点下面有多少个结点,推荐)

    题意:有n个元素,开始每个元素自己一栈,有两种操作,将含有元素x的栈放在含有y的栈的顶端,合并为一个栈.第二种操作是询问含有x元素下面有多少个元素. 6 M 1 6 C 1 M 2 4 M 2 6 C ...

  8. [转]oracle存储过程中update不成功的一个原因

    原文地址:http://lin49940.iteye.com/blog/466626 今天一个同事写oracle 的存储过程遇到了一个问题, 他在里面update 操作不能完成更新的操作, 但是又不会 ...

  9. mysql行转列转换

    http://blog.csdn.net/sinat_27406925/article/details/77507478 mysql 行列转换 ,在项目中应用的极其频繁,尤其是一些金融项目里的报表.其 ...

  10. Spark Streaming 执行流程

    Spark Streaming 是基于spark的流式批处理引擎,其基本原理是把输入数据以某一时间间隔批量的处理,当批处理间隔缩短到秒级时,便可以用于处理实时数据流. 本节描述了Spark Strea ...