我想使用一個子窗口,但是我試圖放在它的組件顯示在「主窗口」或我收到一個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) –