我想创建自定义Window https://vaadin.com/api/com/vaadin/ui/Window.html使用静态工厂样式(或使用单例模式)。
public class MyWindow extends CustomComponent {
private static Window window;
private static MyWindow instance;
public static MyWindow getInstance() {
if (instance == null) {
instance = new MyWindow();
}
return instance;
}
public void show() {
UI.getCurrent().addWindow(window);
}
private MyWindow() {
CustomLayout layout = new CustomLayout("My HTML Layout");
window = new Window("My Window");
window.center();
window.setWidth("615px");
window.setModal(true);
window.setResizable(false);
window.setClosable(true);
window.setContent(layout);
}
}
并调用为MyWindow.getInstance().show();
第一次通话没问题,但关闭此窗口并重新打开后,我在控制台上收到以下错误日志。
Jul 23, 2014 3:42:39 AM com.vaadin.server.DefaultErrorHandler doDefault
SEVERE:
java.lang.IllegalStateException: com.vaadin.ui.Window already has a parent.
at com.vaadin.ui.AbstractComponent.setParent(AbstractComponent.java:469)
at com.vaadin.ui.Window.setParent(Window.java:155)
at com.vaadin.ui.UI.attachWindow(UI.java:501)
at com.vaadin.ui.UI.addWindow(UI.java:490)
那么,我该如何使用自定义Windows https://vaadin.com/api/com/vaadin/ui/Window.html具有静态工厂风格以及如何隐藏和显示Windows https://vaadin.com/api/com/vaadin/ui/Window.html ?
我认为最简单的方法是每次调用 show() 方法时创建一个新的 Window 对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)