Search code examples
javavaadin7

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?


Solution

  • Judging by the code sample in that link and the date of the post (8 years ago), the link you provided is probably for a Vaadin6 problem, as Vaadin7 was released in 2013.

    Anyway, instead of addListener(this); you should use addResizeListener(this);:

    public class WindowWithResizeListener extends Window implements Button.ClickListener, Window.ResizeListener {
    
        public WindowWithResizeListener() {
            center();
            setWidth(600, Unit.PIXELS);
            setHeight(430, Unit.PIXELS);
            setModal(true);
            setResizable(true);
            setImmediate(true);
            addResizeListener(this);
        }
    
        @Override
        public void windowResized(ResizeEvent resizeEvent) {
            Notification.show("Resized!");
    
        }
    
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
    
        }
    }
    

    And there's the output with Vaadin 7.7.9:

    Window with resize listener