首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在GWT CellList中需要多选

在GWT CellList中需要多选
EN

Stack Overflow用户
提问于 2016-06-30 13:17:50
回答 2查看 267关注 0票数 0

我想在一个CellList组件中选择多个单元格;我是GWT新手,有人可以帮我吗?为了获得多选,我如何修改下面的代码?

代码语言:javascript
复制
public class HelloWorld implements EntryPoint {
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday");

public void onModuleLoad() {
    // Create a cell to render each value.
    TextCell textCell = new TextCell();

    // Create a CellList that uses the cell.
    CellList<String> cellList = new CellList<String>(textCell);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a selection model to handle user selection.
    final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
    cellList.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            String selected = selectionModel.getSelectedObject();
            if (selected != null) {
                // Window.alert("You selected: " + selected);
            }
        }
    });

    cellList.setRowCount(DAYS.size(), true);

    // Push the data into the widget.
    cellList.setRowData(0, DAYS);

    // Add it to the root panel.
    RootPanel.get("gwtCellListBox").add(cellList);
}
}
EN

回答 2

Stack Overflow用户

发布于 2016-07-01 02:38:30

首先,您需要一个MultiSelectionModel。然后,如果您希望按住Ctrl键,请使用DefaultSelectionEventManager作为CellPreviewEvent.Handler,该EventTranslator具有始终返回TOGGLEfalse的自定义EventTranslator

票数 1
EN

Stack Overflow用户

发布于 2016-06-30 16:31:25

尝尝这个

代码语言:javascript
复制
public class HelloWorld implements EntryPoint {
private static final List<String> DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday");

public void onModuleLoad() {
    // Create a cell to render each value.
    TextCell textCell = new TextCell();

    // Create a CellList that uses the cell.
    CellList<String> cellList = new CellList<String>(textCell);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a selection model to handle user selection.
     final MultiSelectionModel<String> selectionModel = new MultiSelectionModel<String>();
     cellList.setSelectionModel(selectionModel);
     selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
     public void onSelectionChange(SelectionChangeEvent event) {

        Set<String> selectedItems = selectionModel.getSelectedSet();

        for (String s : selectedItems) {
            System.out.println(s);
            Window.alert("You selected: " + s);
        }
    }
});

    cellList.setRowCount(DAYS.size(), true);

    // Push the data into the widget.
    cellList.setRowData(0, DAYS);

    // Add it to the root panel.
    RootPanel.get("gwtCellListBox").add(cellList);
}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38114487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档