How to close a displaying window from UI?

Thanks for answering~

I mean the window which is active.

use UI.removeWindow method

Thanks for your answer.

But I don’t have the reference to the window. If I do, I can simply call window.close() to close it.

Is there a method that can close the current active window from UI?

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.

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:

[code]
Window window;

@Override
public void addWindow(Window window) throws IllegalArgumentException,
NullPointerException {
window = window;
super.addWindow(window);
}
[/code]This way window should always be the last opened window (not tested).

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.

Thank you for your posting.

I can implement your thoughts in code but how can I get the bringToFront value… I don’t have the reference to that window.

I can’t set the value as static, cause there will be threading issues(This is a web application).

Anyway, thanks so much!!!

I tried but it seems not working.

Nice idea!

You can’t get the bringToFront value atm… as i wrote it is a private member field. So you have to ask the developers if they implement a getter for this field.
At the moment you would have to go with my FocusListener idea