首先,创建示例类:
public class ExampleBean {
private Integer id;
private Button button;
public ExampleBean() {
button = new Button("Test") {
{
addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// code here
}
});
}
}
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setButton(Button button) {
this.id = id;
}
public Button getButton() {
return button;
}
// ToString, Equals and/or HashCode methods if necessary
}
二、创建容器:
private BeanItemContainer<ExampleBean> exampleBeanItemContainer = new BeanItemContainer<ExampleBean>(ExampleBean.class);
接下来,填充容器(将 bean/beans 添加到容器中)并为容器分配表:
exampleBeanItemContainer.addBean(new ExampleBean() {
{
setId(1);
}
});
table.setContainerDataSource(exampleBeanItemContainer);
最后,设置表头和表头可见性:
table.setVisibleColumns(new Object[] { "id", "button" });
table.setColumnHeaders(new String[] { "ID", "Button" });