【发布时间】:2011-06-21 08:10:00
【问题描述】:
我正在尝试使用子窗口,但我尝试放入其中的组件显示在“主窗口”中,或者我收到 java.lang.UnsupportedOperationException。我将向您展示这两种情况。当我需要放入一些真实的组件而不仅仅是标签和按钮时,我想在子窗口中放置一个 HorizontalLayout。
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 在 com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510) 在 com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
...
原因:java.lang.UnsupportedOperationException 在 com.vaadin.ui.CustomComponent.removeComponent(CustomComponent.java:248) 在 com.vaadin.ui.AbstractComponentContainer.addComponent(AbstractComponentContainer.java:207)
...
另一方面,如果我在 setCompositionRoot(layout) 和 myWindow.addComponent(layout) 之间切换位置,Label 和 Button 只会出现在主窗口中,而不是新创建的子窗口中。
我错过了什么?
【问题讨论】: