Java 在窗口中添加自定义组件?
我创建了一个CustomComponent,我想在创建的WindowTemplate中添加这个CustomComponent。我解决了为我的项目的所有窗口创建WindowTemplate的问题,但我仍然无法在template窗口中添加CustomComponent 我正在试这个Java 在窗口中添加自定义组件?,java,frameworks,vaadin,Java,Frameworks,Vaadin,我创建了一个CustomComponent,我想在创建的WindowTemplate中添加这个CustomComponent。我解决了为我的项目的所有窗口创建WindowTemplate的问题,但我仍然无法在template窗口中添加CustomComponent 我正在试这个 /** WindowTemplate for all Window configs app */ public class WindowTemplate extends Window{ public Windo
/** 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;
}
}
如何做到这一点
谢谢。您之所以看不到任何结果,是因为您的所有组件都有相对大小,没有任何组件可以依赖。所以最终一切都被压缩到一个点 其中一种解决方案可能是将hLayout的大小设置为full,这样它将占用窗口中的所有空间,然后定义窗口的大小
public WindowTemplate(String title, CustomComponent cc) {
super(title);
setWidth("200px");
setHeight("200px");
// ...
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setSizeFull();
// ...
public WindowTemplate(String title, CustomComponent cc) {
super(title);
setWidth("200px");
setHeight("200px");
// ...
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setSizeFull();
// ...