了解Vaadin弹出窗口

时间:2016-10-16 19:38:07

标签: java vaadin vaadin7 vaadin6

我有两个带两个窗口的按钮。按钮应显示每个窗口的内容。我想按钮显示按钮一个内容,第二个按钮显示按钮一个内容。如何将按钮单击方法绑定到单击侦听器?
----------------------------编辑---------------

建议编辑后按钮两个显示“这是按钮2'但按钮1只显示一个窗口,这是按钮1永远不会出现'。

    @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 个答案:

没有答案