gpt4 book ai didi

java - Vaadin - 如果我使用 AbsoluteLayout,则不会显示表数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:09 28 4
gpt4 key购买 nike

目前,我在使用 Vaadin Table 时遇到了一个非常奇怪的问题。如果我在表中使用 AbsoluteLayout 数据不会显示,但如果我使用即 Horizo​​ntalLayout,数据会完美显示。这有效:

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;

public class MyComposite extends CustomComponent {


@AutoGenerated
private HorizontalLayout mainLayout;
@AutoGenerated
private Table table;


public MyComposite() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here

table.addContainerProperty("First Name", String.class, null);
table.addContainerProperty("Last Name", String.class, null);
table.addContainerProperty("Year", Integer.class, null);

table.addItem(new Object[] { "Nicolaus", "Copernicus",
new Integer(1473) }, new Integer(1));
table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) },
new Integer(2));

}

@AutoGenerated
private HorizontalLayout buildMainLayout() {
// common part: create layout
mainLayout = new HorizontalLayout();
mainLayout.setStyleName("blue");
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
mainLayout.setMargin(false);

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

// table
table = new Table();
table.setImmediate(false);
table.setWidth("100.0%");
table.setHeight("100.0%");
mainLayout.addComponent(table);

return mainLayout;
}

}

但这不是:

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Table;

public class MyComposite extends CustomComponent {


@AutoGenerated
private AbsoluteLayout mainLayout;
@AutoGenerated
private Table table;
public MyComposite() {
buildMainLayout();
setCompositionRoot(mainLayout);
// TODO add user code here

table.addContainerProperty("First Name", String.class, null);
table.addContainerProperty("Last Name", String.class, null);
table.addContainerProperty("Year", Integer.class, null);

table.addItem(new Object[] { "Nicolaus", "Copernicus",
new Integer(1473) }, new Integer(1));
table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) },
new Integer(2));

}

@AutoGenerated
private AbsoluteLayout buildMainLayout() {
// common part: create layout
mainLayout = new AbsoluteLayout();
mainLayout.setStyleName("blue");
mainLayout.setImmediate(false);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");

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

// table
table = new Table();
table.setImmediate(false);
table.setWidth("100.0%");
table.setHeight("100.0%");
mainLayout.addComponent(table);

return mainLayout;
}

}

两种情况下都会显示列的名称。有人能告诉我为什么会这样吗?提前致谢。

最佳答案

我能够重现您的问题。似乎 Vaadin 的家伙在这里描述了原因: Vaadin book

引用:

A layout that contains components with percentual size must have a defined size!

If a layout has undefined size and a contained component has, say, 100% size, the component will try to fill the space given by the layout, while the layout will shrink to fit the space taken by the component, which is a paradox. This requirement holds for height and width separately. The debug mode allows detecting such invalid cases; see Section 11.3.5, “Inspecting Component Hierarchy”

对于 AbsoluteLayout,到目前为止我发现的唯一解决方法是将表格尺寸设置为一些固定值。

关于java - Vaadin - 如果我使用 AbsoluteLayout,则不会显示表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23082371/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com