当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Capturing window events using AWTEvent.WINDOW_EVENT_MASK

问题描述:

For capturing window events on global level, I am doing

 Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

@Override

public void eventDispatched(AWTEvent event) {

System.out.println(event);

System.out.println(Arrays.toString(Window.getWindows()));

}

}, AWTEvent.WINDOW_EVENT_MASK);

However, when an internal frame window is opened, I am not receiving any event. Also, Window.getWindows() is not returning internal frame windows.

  1. How can I capture the events (opening and closing) from InternalFrame windows on a global level?
  2. When I try to narrow down the events using AWTEvent.WINDOW_STATE_EVENT_MASK, I am not receiving any event. I am specifically interested in Window opening and closing event. How can I achieve this?

网友答案:

For JInternalFrame opening and close, no WindowEvent is pushed, because it is not a Window child. Using the AWTEvent.CONTAINER_EVENT_MASK parameter in AWTEventListener you'll receive ContainerEvent[COMPONENT_ADDED] and ContainerEvent[COMPONENT_REMOVED] for adding and removing the JInternalFrames respectively:

Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
    @Override
    public void eventDispatched(AWTEvent event) {
        System.out.println(event);
    }
}, AWTEvent.CONTAINER_EVENT_MASK);
分享给朋友:
您可能感兴趣的文章:
随机阅读: