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)
andwindowDeactivated(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/