Why Vaadin Window.ResizeListener is not invoked

I have the following class as following:-

public class ExchangeWindow extends Window implements Button.ClickListener, Window.ResizeListener {

public ExchangeWindow() {
center();
setWidth(600, Unit.PIXELS);
setHeight(430, Unit.PIXELS);
setModal(true);
setResizable(true);
setImmediate(true);
addListener(this);
}

@Override
public void windowResized(ResizeEvent resizeEvent) {
if(left.isVisible()) {
//left.setWidth(600, UNITS_PIXELS);
exchangeTable.setWidth(600, UNITS_PIXELS);
}
}

I found this link: https://vaadin.com/forum/thread/117302 . I guess my code is similar to this. windowResized method is never called whether I set setImmediate(true); or setImmediate(false);

I am using Vaadin 7.

What is wrong? How to catch the resize event notification?

I have created a simple testing project with Vaadin 7.7.13, with the following class:

public class ExchangeWindow extends Window implements Button.ClickListener, Window.ResizeListener {

    public ExchangeWindow() {
        center();
        setWidth(600, Unit.PIXELS);
        setHeight(430, Unit.PIXELS);
        setModal(true);
        setResizable(true);
        setImmediate(true);
        addListener(this);
    }

    @Override
    public void windowResized(ResizeEvent resizeEvent) {
        System.out.println(new Date());
        System.out.println("Window resized: " + resizeEvent.getWindow().getWidth() + "x" + resizeEvent.getWindow().getHeight());
    }

    @Override
    public void buttonClick(Button.ClickEvent clickEvent) {
        System.out.println("Button clicked: " + clickEvent);
    }
}

When I resize the Window, it correctly prints the resized events as follows:

Fri Apr 20 08:38:50 EEST 2018
Window resized: 174.0x81.0
Fri Apr 20 08:39:02 EEST 2018
Window resized: 942.0x598.0

The resize event catching code seems correct. Which version of Vaadin 7 are you using?

Thank a lot Martin. But I get the event only if I try to resize the window by dragging the mouse. It doesn’t fire this event when I click maximise/restore button. How can I catch maximise/restore button click?

Unfortunately maximise/restore button click won’t fire the window-resize event. Luckily it fires WindowModeChangeEvent; however even when maximized, the window will still reports the unmaximized width. But we can devise a workaround to poll for the value of Page.getCurrent().getBrowserWindowWidth() when the Window is maximized. The following code snippet summarizes the idea:

public class ExchangeWindow extends Window {

    public ExchangeWindow() {
        center();
        setWidth(600, Unit.PIXELS);
        setHeight(430, Unit.PIXELS);
        setModal(true);
        setResizable(true);
        setImmediate(true);
        addResizeListener(event -> onWindowResize());
        addWindowModeChangeListener(event -> onWindowResize());
    }

    private void onWindowResize() {
        System.out.println(new Date());
        final float width = getWindowMode() == WindowMode.MAXIMIZED ? Page.getCurrent().getBrowserWindowWidth() : getWidth();
        System.out.println("Window width: " + width);
    }
}