Window Close

It’s possible to close all opened windows?

I try to use this when I will change my view, so every time I change e view I need to close any window opened:

Collection<Window> windowList = UI.getCurrent().getWindows();
for(Window www : windowList){

But I got this error:

java.util.ConcurrentModificationException: null
at java.util.LinkedHashMap$LinkedHashIterator.nextNode( ~[na:1.8.0_162]

at java.util.LinkedHashMap$ ~[na:1.8.0_162]

This is most likely happening because when window is closed it is removed from the Map backing UI.getCurrent().getWindows();, breaking the iterator.

This can be worked around (in a dirty way :wink: with:

Collection<Window> windowList = new ArrayList<>(UI.getCurrent().getWindows());
for(Window www : windowList){

In this case you’ll have a copy of window list, and window.close() will not affect it.

Artem Godin I already try this and get the same error

What is the context where you call it? I tried Artems solution and it worked (encapsulating it in another list).

Maybe try it with an array or an iterator instead.


Collection<Window> windows = UI.getCurrent().getWindows();

Object[] array = windows.toArray();
for (int i = 0; i < array.length; i++) {


Iterator<Window> windowList = new ArrayList<>(UI.getCurrent().getWindows()).iterator();
while (windowList.hasNext()) {
	Window next =;