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

最新文章

  1. JS函数运行在它们被定义的作用域内,而不是它们被执行的作用域内
  2. eclipse+spket+Extjs4.2.1开发环境搭建
  3. ORA-03113解决方法
  4. 151008:javascript不明白的地方
  5. Java魔法堂:自定义和解析注解
  6. 转 Citrix XenCenter安装VM之挂载ISO详解
  7. [GeekBand]C++高级编程技术(2)
  8. CF Covered Path (贪心)
  9. BestCoder Round #49
  10. 腾讯云上PhantomJS用法示例
  11. 【Docker】 积累
  12. 论C++的智能指针
  13. 利用box-shadow属性实现页面层叠效果
  14. git提交忽略某些文件或文件夹
  15. javascript 跨域 的几种方法
  16. git 线上回滚问题纪要
  17. 乘风破浪:LeetCode真题_026_Remove Duplicates from Sorted Array
  18. 0005python中的静态方法和类方法
  19. redis通过dump.db文件 进行数据替换 复制
  20. raspberry pi 树莓派作为比特比矿机

热门文章

  1. STL之string类详解
  2. 每日英语:A Buying Guide to Air-Pollution Masks
  3. python(35):多线程读取文件
  4. VirtualBox与VMWare网络冲突
  5. spark on alluxio和MR on alluxio测试(改进版)【转】
  6. 搜索页面scroll下拉时候进行刷新,显示更多搜索值
  7. H3C AP实现定时重启
  8. Zabbix之Python发送邮件
  9. JAVA-JSP内置对象之request范围
  10. 慢慢来,比较快。四年Android,共勉。