Garrett Hall
Garrett Hall

Reputation: 30022

Is there a way to listen globally for newly opened windows in swing?

Similar to how I could listen to key presses globally using KeyboardFocusManager is there a way to listen globally for any opened (setVisible call) JFrame or Window in Swing?

I could poll Window.getWindows() to do this, but I was wondering if I could do this in an event-driven way.

Upvotes: 3

Views: 152

Answers (1)

svaor
svaor

Reputation: 2245

Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
    @Override
    public void eventDispatched(AWTEvent event) {
        System.out.println(event);
    }
}, AWTEvent.WINDOW_EVENT_MASK);

Upvotes: 5

Related Questions