Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

How to close a displaying window from UI?

Weiqiang Xiong
7 years ago May 21, 2015 2:21pm

Thanks for answering~

Weiqiang Xiong
7 years ago May 21, 2015 2:25pm
Emmanuelle Victoria
7 years ago May 21, 2015 2:28pm

use UI.removeWindow method

Weiqiang Xiong
7 years ago May 21, 2015 2:36pm
Emmanuelle Victoria
7 years ago May 21, 2015 3:04pm

I can't seem to see any. Will using setCloseShortcut in a window okay for you? If you set the esc key as the close shortcut, the active window will close upon pressing esc.

Marius Reinwald
7 years ago May 21, 2015 3:14pm

Not sure how well this will work but you could overwrite addWindow() in your UI class and then store a reference of the last opened Window (or store an array and remove them from it an overwritten removeWindow method) like:

Window window;

@Override
public void addWindow(Window window) throws IllegalArgumentException,
         NullPointerException {
    window = window;
    super.addWindow(window);
}

This way window should always be the last opened window (not tested).

Felix Kalka
7 years ago May 21, 2015 4:04pm

But it will not give the last active Window...
Window has the private field bringToFront.
You could file a change request to give this field a getter (and give bringToFront on attach an initial value, if not already done), then you could iterate over all attached windows and find the window with the biggest bringToFront value...

Atm i guess it would be only possible by adding FocusListener on the window and on all Components inside the window that updates a reference to the focused window in the UI. I can provide you some code if you don't get what i mean.

Weiqiang Xiong
7 years ago May 21, 2015 5:02pm
Weiqiang Xiong
7 years ago May 21, 2015 5:22pm
Felix Kalka
7 years ago May 21, 2015 10:31pm