Understanding Vaadin pop up windows

106 views Asked by At

I have two buttons with two windows. The buttons should show content per their respective windows. I would like button to show button one content and the second button to show button one content. How do I tie the button click method to click listener?
----------------------------edit---------------

After the suggested edit Button two shows 'This is Button 2' but Button one just shows a window and 'This is Button 1 never appears'.

    @Theme("mytheme")
    public class MyUI extends UI implements Button.ClickListener {

     final Button button = new Button("Click Me");
     final Button button2 = new Button("Click Me");

     final FormLayout content = new FormLayout();
     final VerticalLayout layout = new VerticalLayout();


    @Override
    protected void init(VaadinRequest vaadinRequest) {

        final Window window = new Window("Window");
        final Window window2 = new Window("Window");

       window.setContent(content);
       window2.setContent(content);

       button.addClickListener( e -> {
       content.addComponent(new Label("This is Button 1"));
       UI.getCurrent().addWindow(window);
    });

      button2.addClickListener( f -> {
      content.addComponent(new Label("This is Button 2"));
       UI.getCurrent().addWindow(window2);
    });

      layout.addComponents(button, button2);            
        layout.setMargin(true);
        layout.setSpacing(true);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyUIServlet extends VaadinServlet {
    }


}
0

There are 0 answers