gpt4 book ai didi

java - CellList 保持选定的单元格被选中?

转载 作者:太空宇宙 更新时间:2023-11-04 07:12:03 24 4
gpt4 key购买 nike

我使用MGWT CellList效果完美。

我遇到以下问题。如何保持选定的单元格处于选中状态,以便在用户释放单元格后仍保持选中状态?

这是我的实现:

CellList<Item> myCellList = new CellList<Item>(new ItemCell());

我的 ItemCell 类:

public class ItemCell implements Cell<Item> {

private static Template TEMPLATE = GWT.create(Template.class);

public interface Template extends SafeHtmlTemplates {
@SafeHtmlTemplates.Template("<div>{0}</div>")
SafeHtml content(String cellContents);
}

@Override
public void render(SafeHtmlBuilder safeHtmlBuilder, Item model) {
SafeHtml content = TEMPLATE.content(model.getName());

safeHtmlBuilder.append(content);

}

@Override
public boolean canBeSelected(Item model) {
return true;
}

}

我的元素类别:

public class Item {

private String name;

public Item() {
setName("");
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

最佳答案

您想要的是选择处理程序。如果你想要单选使用 SingleSelectionHandler,如果你想要多选使用 MultiSelectionHandler, 示例代码:

 SelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
cellList.setSelectionModel(selectionModel);

如果您想对选择执行任何操作,可以在此处执行

selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
/** Do your thing here **/
selectionModel.getSelectedObject(); //for single Selection
selectionModel.getSelectedSet(); //for multiple Selection
}
});

关于java - CellList 保持选定的单元格被选中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20508281/

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