gpt4 book ai didi

java - 如何从单元格表中删除一行

转载 作者:搜寻专家 更新时间:2023-10-31 08:21:18 25 4
gpt4 key购买 nike

一开始我用的是Grid。创建新版本的 GWT 后,我想替换 CellTable 上的 Grid。

最佳答案

查看 javadoc了解详情。我的例子就像你在那里找到的那​​个(只是有点扩展):

public void onModuleLoad() {
final CellTable<Row> table = new CellTable<Row>();

TextColumn<Row> firstColumn = new TextColumn<Starter.Row>() {

@Override
public String getValue(Row object) {
return object.firstColumn;
}
};
table.addColumn(firstColumn, "header one");

TextColumn<Row> secondColumn = new TextColumn<Starter.Row>() {

@Override
public String getValue(Row object) {
return object.secondColumn;
}
};
table.addColumn(secondColumn, "header two");

TextColumn<Row> thirdColumn = new TextColumn<Starter.Row>() {

@Override
public String getValue(Row object) {
return object.thirdColumn;
}
};
table.addColumn(thirdColumn, "header three");

table.setRowCount(getList().size());
final ListDataProvider<Row> dataProvider = new ListDataProvider<Starter.Row>(getList());
dataProvider.addDataDisplay(table);

final SingleSelectionModel<Row> selectionModel = new SingleSelectionModel<Starter.Row>();
table.setSelectionModel(selectionModel);

Button btn = new Button("delete entry");
btn.addClickHandler(new ClickHandler() {

@Override
public void onClick(ClickEvent event) {
Row selected = selectionModel.getSelectedObject();
if (selected != null) {
dataProvider.getList().remove(selected);
}
}
});

RootPanel.get().add(table);
RootPanel.get().add(btn);

}

private class Row {

private String firstColumn;
private String secondColumn;
private String thirdColumn;

public Row(String firstColumn, String secondColumn, String thirdColumn) {
this.firstColumn = firstColumn;
this.secondColumn = secondColumn;
this.thirdColumn = thirdColumn;
}

}

private LinkedList<Row> getList() {
LinkedList<Row> list = new LinkedList<Row>();
list.add(new Row("first", "entry", "foo"));
list.add(new Row("second", "entry", "foo"));
list.add(new Row("third", "entry", "foo"));
list.add(new Row("fourth", "entry", "foo"));
return list;
}

关于java - 如何从单元格表中删除一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345890/

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