如果其他布局组件设置为展开,则Vaadin标签将隐藏
如果我使用以下代码使用Vaadin创建UI如果其他布局组件设置为展开,则Vaadin标签将隐藏,vaadin,Vaadin,如果我使用以下代码使用Vaadin创建UI @Override protected void init(VaadinRequest request) { HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addComponent(new Label("Why am I not shown?")); Button button = new Button("expandi
@Override
protected void init(VaadinRequest request) {
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.addComponent(new Label("Why am I not shown?"));
Button button = new Button("expanding button");
horizontalLayout.addComponent(button);
horizontalLayout.setExpandRatio(button, 1);
horizontalLayout.setWidth(100, Unit.PERCENTAGE);
setContent(horizontalLayout);
}
我添加到horizontalLayout
的标签不会显示在创建的UI中。为什么呢?在这种情况下,我希望标签采用所需的宽度,按钮采用剩余的宽度。但标签根本没有显示出来
请不要问我为什么要展开按钮。这只是一个MCVE,我的真实UI有些复杂。默认情况下,
按钮的大小未定义。因此,空间将由扩展比为0的100%
大小标签(默认情况下)和扩展比为1的按钮的多余空间共享。因此,所有空间都被赋予按钮的多余空间
使用Label.setSizeUndefined()
将标签设置为具有未定义的大小,并将按预期工作
请注意,使用展开比时,相对大小的组件可能会丢失所有空间
例如:
HorizontalLayout horizontalLayout = new HorizontalLayout();
Label l1 = new Label("one");
Label l2 = new Label("two");
Label l3 = new Label("three");
horizontalLayout.addComponent(l1);
horizontalLayout.addComponent(l2);
horizontalLayout.addComponent(l3);
horizontalLayout.setExpandRatio(l2, 1);
将仅显示标签“两个”。默认情况下,按钮的大小未定义。因此,空间将由扩展比为0的100%
大小标签(默认情况下)和扩展比为1的按钮的多余空间共享。因此,所有空间都被赋予按钮的多余空间
使用Label.setSizeUndefined()
将标签设置为具有未定义的大小,并将按预期工作
请注意,使用展开比时,相对大小的组件可能会丢失所有空间
例如:
HorizontalLayout horizontalLayout = new HorizontalLayout();
Label l1 = new Label("one");
Label l2 = new Label("two");
Label l3 = new Label("three");
horizontalLayout.addComponent(l1);
horizontalLayout.addComponent(l2);
horizontalLayout.addComponent(l3);
horizontalLayout.setExpandRatio(l2, 1);
将仅显示标签“2”