用另一个窗口打开一个窗口?

时间:2013-11-27 10:34:24

标签: java vaadin

我的vaadin项目中有一个窗口,现在我想打开另一个窗口。

我正在尝试这个。

public class MyWindow extends Window {
    /** this is a window that I want open */ 
    public MyWindow() {
        super("MyWindow");
        center();
        VerticalLayout vLayout = new VerticalLayout();
        vLayout.addComponent(new Label("MyWindow is opened");
        setContent(vLayout);
    }
}

public class OpenMyWindow extends Window {
    /** this is a window that should open MyWindow */
    private Button btnOpenMyWindow;
    public OpenMyWindow() {
        super("OpenMyWindow");
        center();
        VerticalLayout vLayout = new VerticalLayout();
        btnOpenMyWindow = new Button("Open My Window");
        btnOpenMyWindow.addClickListener(new Button.ClickListener() {   
            @Override       
            public void buttonClick(ClickEvent event) {
                new MyWindow().setVisible(true);
            }     
        });
        vLayout.addComponent(btnOpenMyWindow);
        setContent(vLayout);
    } 
}

怎么做?

1 个答案:

答案 0 :(得分:2)

您可以使用UI.addWindow方法:

...
MyWindow myWindow = new MyWindow();
UI.getCurrent().addWindow(myWindow);
...

请查看Vaadin Book chapter on subwindows.