java - windowActivated 和 windowFocusGained 之间的区别

标签 java window listener

windowActivated 方法(从 WindowListener 实现)和 windowGainedFocus(从 WindowFocusListener 实现)之间的主要区别是什么?

Java 文档说:

窗口获得焦点:

Invoked when the Window is set to be the focused Window, which means that the Window, or one of its subcomponents, will receive keyboard events.

窗口激活:

Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

但是有什么区别呢?或者正如它所说,聚焦窗口是一种激活窗口?

提前致谢!

最佳答案

来自How to Write Window Listeners这也反射(reflect)了您问题中的引用:

windowActivated(WindowEvent) and windowDeactivated(WindowEvent):

Called just after the listened-to window is activated or deactivated, respectively. These methods are not sent to windows that are not frames or dialogs. For this reason, the windowGainedFocus and windowLostFocus methods to determine when a window gains or loses the focus are preferred.

<小时/>

因此,windowActivated在窗口是框架或对话框时执行,而windowGainedFocus适用于所有类型。

关于java - windowActivated 和 windowFocusGained 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31800601/

相关文章:

javascript - 对 spring @ResourceMapping 方法进行 react ,未使用相同的请求参数调用

java - JVM 版本 1.5.0_30 不适合本产品。需要 OSX 1.6 或更高版本

jsf - 'official' SEAM 监听 JSF-SEAM 阶段的方式是什么?

java实时优先级高于应有的优先级

java - 如何添加最新的依赖ZXing android嵌入(2017)

macos - 在 Qt 中设置超出屏幕分辨率的窗口大小

emacs 以编程方式更改窗口大小

linux - GPU 如何渲染到正确的窗口?

java - 尝试创建监听器模式样式类,观察者不会收到通知

java - 如何在 Java 中实现一个数据库监听器