【问题标题】:Add CustomComponent in Window?在窗口中添加自定义组件?
【发布时间】:2013-11-28 13:31:45
【问题描述】:

我创建了一个 CustomComponent,我想在创建的 WindowTemplate 中添加这个 CustomComponent。我解决了为我的项目的所有窗口创建一个 WindowTemplate,但我仍然无法在模板窗口中添加 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());
}
}

如何做到这一点?

谢谢。

【问题讨论】:

    标签: java frameworks vaadin


    【解决方案1】:

    您没有看到任何结果的原因是您的所有组件都有相对大小,并且没有任何依赖项。所以最终一切都被挤压到一个点。

    其中一种解决方案可能是将 hLayout 的大小设置为 full,以便它占据窗口中的所有空间,然后定义窗口的大小。

    public WindowTemplate(String title, CustomComponent cc) {
        super(title);       
        setWidth("200px");
        setHeight("200px");
    
        // ...
    
        HorizontalLayout hLayout = new HorizontalLayout();
        hLayout.setSizeFull();
    
        // ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      • 2013-07-20
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      相关资源
      最近更新 更多