Difference between windowActivated and windowFocusGained

后端 未结 2 410
攒了一身酷
攒了一身酷 2021-01-25 08:50

What\'s the main difference between the method windowActivated (implemented from WindowListener) and windowGainedFocus (implemented from WindowFocusListener)?

The Java d

2条回答
  •  情歌与酒
    2021-01-25 09:08

    From How to Write Window Listeners which reflects the quote in your question aswell:

    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.


    So windowActivated is only executed when the window is a frame or dialog, while the windowGainedFocus is for all types.

提交回复
热议问题