0

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 {
    }


}
spring_hiber
  • 109
  • 1
  • 2
  • 12
  • Remove the `buttonClick` method (and interface) from your `UI` implementation, and move the corresponding `content.addComponent` lines in the appropriate click listeners defined in your `init` method? – Morfic Oct 17 '16 at 12:17
  • You can not share `content`. You need two different components for the two windows. If you add the `content` to the second window, you take it away from the first one therefor you see no window. – cfrick Oct 17 '16 at 14:44

0 Answers0