gpt4 book ai didi

java - 如何将表格添加到布局中

转载 作者:行者123 更新时间:2023-12-01 09:42:26 25 4
gpt4 key购买 nike

我在自己的类 FileUploaderResultsTable.java 中创建了一个表,如下所示:

public class FileUploaderResultsTable extends Table
{

public FileUploaderResultsTable()
{

Table resultTable = new Table("Rendering table");
resultTable.addStyleName("testTable2");
resultTable.addContainerProperty("Name", String.class, null);
resultTable.addContainerProperty("Mag", Float.class, null);

resultTable.addItem(new Object[]{"Canopus", -0.72f}, 2);
resultTable.addItem(new Object[]{"Arcturus", -0.04f}, 3);
resultTable.addItem(new Object[]{"Alpha Centauri", -0.01f}, 4);

resultTable.setPageLength(resultTable.size());
System.out.println("table created");
}

我有另一个类 FileUploaderComponent.java,其中有一个添加到 Window 对象的垂直布局。我正在尝试显示上面的表格,因此在 FileUploaderComponent.java 中我创建了一个 FileUploaderResultsTable 对象,如下所示:

public class FileUploaderComponent extends AbstractJavaScriptComponent
{

...
private VerticalLayout myLayout = new VerticalLayout();
private FileUploaderResultsTable resultsTable = new FileUploaderResultsTable();
...
public void addTable(){
myLayout.addComponent(resultsTable);
}

}

myLayout 然后被添加到另一个函数中的新窗口对象中。该机制之所以有效,是因为我添加了文本字段等其他元素,但由于某些原因,该表无法正确添加。在 DOM 中,我可以看到有一个表,但它是空的,并且没有指定类名。说实话,通常如果我想将另一个类中的组件添加到布局中,我通常会将该组件称为 resultsTable.resultTable ,因此使用 object.component 语法而不仅仅是 resultsTable ,但编译器不喜欢这样。那么,是否有另一种方法可以将表格作为组件添加到布局中,或者我只是在做一些愚蠢的事情?

最佳答案

您使用扩展类的方式是错误的。试试这个:

public class FileUploaderResultsTable extends Table
{

public FileUploaderResultsTable()
{
setCaption("Rendering table");
addStyleName("testTable2");
addContainerProperty("Name", String.class, null);
addContainerProperty("Mag", Float.class, null);

addItem(new Object[]{"Canopus", -0.72f}, 2);
addItem(new Object[]{"Arcturus", -0.04f}, 3);
addItem(new Object[]{"Alpha Centauri", -0.01f}, 4);

setPageLength(resultTable.size());

System.out.println("table created");
}
}

关于java - 如何将表格添加到布局中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38349502/

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