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/53839062/

相关文章:

Java:如何使应用程序范围的 GregorianCalendar 线程安全?

java - 如何在java中设置打印机边距

java - 如何处理spring-security-oauth2的版本升级?

java - 当它们位于不同的类中时,如何从另一个JPanel事件监听器更改JPanel的组件?

javascript - Extjs 使用 addCls() 改变绘图点的颜色,几乎搞定了

paypal - Paypal 中的 IPN 与 PDT

java - Java 中的 Git Diff 命令

javascript - 如果屏幕尺寸大于 X,则运行脚本

css - 模态窗口 javascript css 覆盖

c++ - QQuickWindow 上下文属性?