我想使用一个子窗口,但是我试图放在它的组件显示在“主窗口”或我收到一个java.lang.UnsupportedOperationException。我会告诉你两种情况。我想在子窗口中放置一个HorizontalLayout,当我需要放入一些真实的组件时,而不仅仅是一个标签和一个按钮。Vaadin:子窗口
public class SubWindow extends CustomComponent {
Window mainWindow; // Reference to main window
Window myWindow; // The window to be opened
public SubWindow(Window main) {
mainWindow = main;
createWindow();
}
public void createWindow() {
myWindow = new Window("My Dialog");
HorizontalLayout layout = new HorizontalLayout();
// Add the window inside the main window.
mainWindow.addWindow(myWindow);
layout.addComponent(new Label("A label"));
layout.addComponent(new Button("Ok"));
// The composition root MUST be set
setCompositionRoot(layout);
myWindow.addComponent(layout);
}
}
当我运行这一点,并打开使用
window = new Window("Title");
setMainWindow(window);
window.addComponent(new SubWindow(window));
我得到一个新的子窗口
重度:终端错误:
com.vaadin.event.ListenerMethod $ MethodException
原因:java.lang.UnsupportedOperationException at c Java的:om.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510) 在com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
...
所致。 lang.UnsupportedOperationException 在com.vaadin.ui.CustomComponent.removeComponent(CustomComponent.java:248) 在com.vaadin.ui.AbstractComponentContainer.addComponent(AbstractComponentContainer.java:207)
...
另一方面,如果我在setComp之间切换ositionRoot(布局)和myWindow.addComponent(布局),Label和Button只是在主窗口而不是新创建的子窗口中。
我错过了什么?
感谢您的回应,现在它就像一个魅力。对于有同样问题的人,这里有一个关于[Sub windows]的好教程(http://vaadin.com/tutorial/-/chapter/skeleton.subwindows.html) –