2013-11-28 41 views
0

我創建了一個CustomComponent,我想在創建的WindowTemplate中添加這個CustomComponent。我解決了爲我的項目的所有窗口創建WindowTemplate,但我仍然無法在模板窗口中添加CustomComponent。在窗口中添加CustomComponent?

我正在試着這個。

/** WindowTemplate for all Window configs app */ 
public class WindowTemplate extends Window{ 
    public WindowTemplate(String title, CustomComponent cc){ 
    super(title);  
    setSizeUndefined(); 
    setModal(true); 
    setClosable(false); 
    setDraggable(false); 
    setResizable(false);   
    setIcon(new ThemeResource("../icons/ibg_icon.png")); 
    HorizontalLayout hLayout = new HorizontalLayout(); 
    hLayout.addComponent(cc); 
    setContent(hLayout); 
    center(); 
} 
} 


/** my customcomponent */ 
public class CadCur extends CustomComponent { 
    private AbsoluteLayout mainLayout; 
    private TextField email; 

public CadCur() { 
    buildMainLayout(); 
    setCompositionRoot(mainLayout); 
} 

@AutoGenerated 
private AbsoluteLayout buildMainLayout() {  
    mainLayout = new AbsoluteLayout(); 
    mainLayout.setImmediate(false); 
    mainLayout.setWidth("100%"); 
    mainLayout.setHeight("100%"); 

    // top-level component properties 
    setWidth("100.0%"); 
    setHeight("100.0%"); 

    // email 
    email = new TextField(); 
    email.setCaption("Email"); 
    email.setImmediate(false); 
    email.setWidth("50.0%"); 
    email.setHeight("-1px"); 
    email.setRequired(true); 
    mainLayout.addComponent(email, "top:96.0px;left:43.0px;"); 

    return mainLayout; 
} 

}

/** a UI class */ 
public class PrincipalUI extends UI{ 
    @Override 
    protected void init(VaadinRequest request) {    
     getCurrent().addWindow(new WindowTemplate("MyWindow", new CadCur()); 
} 
} 

如何做到這一點?

謝謝。

回答

0

你沒有看到任何結果的原因是因爲你的所有組件都有相對大小,他們都沒有任何依賴。所以最終所有東西都擠壓到一點。

其中一種解決方案可能是將hLayout的大小設置爲full,以便佔用窗口中的所有空間,然後定義窗口的大小。

public WindowTemplate(String title, CustomComponent cc) { 
    super(title);  
    setWidth("200px"); 
    setHeight("200px"); 

    // ... 

    HorizontalLayout hLayout = new HorizontalLayout(); 
    hLayout.setSizeFull(); 

    // ...