Focus component when closing modal subwindow


I’m having an issue using subwindows in Vaadin 7+ (currently I’m developing on 7.3.0 stable but I already had this problem in 7.2)
I have a save button which opens a modal subwindow when gaining focus.
When I close this subwindow the focus returns to the last focused component outside (the save button in this case) so the subwindow opens another time because of the save button regaining focus.
I’ve tried to call “anotherComponent.focus()” but this doesn’t help.

Can you please suggest me any workaround for this?

Here is an example code:

final UI ui = UI.getCurrent();
final TextField tf = new TextField();
final Button save = new Button("save");

... building layout ...

save.addFocusListener((e) -> openWindow());

// method which opens the subwindow:
private void openWindow() {
final Window w = new Window();
w.setContent(new Button(“close me”, new ClickListener() {

        public void buttonClick(final ClickEvent event) {
            // the textfield does not gain the focus



This is the same with my case. I’m using Vaadin 7.3.5

This is the same in my case. I am using Vaadin 7.3.8.

I have textField. On focusListener I popup window. When that window is closed, focus is back in textField, therefore another popup window. Any idea how to “unfocus” textField. I have tried to focus “dummy” button, but works only if I put a break point to dummyButton.focus();

Any idea?

I have similar problem.

Me too. In my case I open a window when a textfield gains focus. I want the window to be hidden when the textfield loses focus. But when the BlurEvent is called and I close the window, focus is shifted back to the TextField and the window is displayed again. I’m having to jump through hoops to make a usable UI where the focus stays with the TextField, which is not what I’m really after.

For those who are still struggling with this:

Instead of trying to set a focus from the CloseListener itself, set a boolean flag instead, and in the FocusListener of the opening component check that flag. Then, if the flag shows you that you are indeed arriving back from the Window instead of otherwise navigating there, set the focus where you want it to go and reset the flag.

The default focus behaviour is an accessibility feature for making keyboard navigation easier.