我如何把“(全部)选择全部” SWT表头中的复选框? [英] How can I put a "(de)select all" check box in an SWT Table header?

查看:911
本文介绍了我如何把“(全部)选择全部” SWT表头中的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SWT表,我使用 SWT.CHECK 样式实例化,以便在每行旁边显示一个复选框。我的用户已请求表格标题行中的另一个复选框,以便允许他们通过一次点击选择/取消选择所有行。

I have an SWT Table that I'm instantiating with the SWT.CHECK style in order to display a check box next to every row. My users have requested another check box in the header row of the table in order to allow them to select/deselect all the rows with one click.

我看不到任何明显的方法,我只通过Google找到了Swing / JTable示例。有谁知道如何做到这一点?

I can't see any obvious way to do it, and I've only found Swing/JTable examples through Google. Does anyone know how to do this? I'm hoping it's possible without re-implementing Table or falling back on a header context menu.

推荐答案

只需创建两个图像即可,不需要重新实现表格或回退到标题上下文菜单。复选框。第一个没有刻度线,第二个有tick.Now添加第一个图像到tableColumn标题。之后,添加监听器到tableColumn以这样的方式,当你第一次单击按钮, table.selectALL()方法应该被触发,同时更改tableColumn标题图像到第二个。当您再次单击按钮调用 table.deSelectAll()方法,并将第一个图像替换为tableColumn标题。

Just create two images of check box. First one without a tick and second one having a tick.Now add the first image to the tableColumn header. After that add listener to tableColumn in such a way that when you click button for the first time, table.selectALL() method should be fired along with changing the tableColumn header image to second one. When you click button again call table.deSelectAll() method and replace the tableColumn header with the first image.

您可以使用此条件:


当单击复选框(image)时,使用for循环检查
选中表中的复选框。如果发现任何人,
检查,然后fire table.deSelectAll()方法,否则fire
table.selectAll()方法。

When the checkbox(image) is clicked, use a for loop to check whether, any of the checkboxes in the table is checked. if anyone is found checked then fire table.deSelectAll() method , else fire table.selectAll() method.


$ b b

在表/ widow调整大小期间,checkbox不会有任何问题。

There will not be any problem for the "checkbox" during table/widow resizing.

tableColumn0.addListener(SWT.Selection, new Listener() {
    @Override
    public void handleEvent(Event event) {
        // TODO Auto-generated method stub
        boolean checkBoxFlag = false;
        for (int i = 0; i < table.getItemCount(); i++) {
            if (table.getItems()[i].getChecked()) {
                checkBoxFlag = true;
            }
        }

        if (checkBoxFlag) {
            for (int m = 0; m < table.getItemCount(); m++) {
                table.getItems()[m].setChecked(false);
                tableColumn0.setImage(new Image(Display.getCurrent(),
                        "images/chkBox.PNG"));

                table.deselectAll();

            }
        } else {
            for (int m = 0; m < table.getItemCount(); m++) {
                table.getItems()[m].setChecked(true);
                tableColumn0.setImage(new Image(Display.getCurrent(),
                        "images/chkBox2.PNG"));

                table.selectAll();
            }
        }

    }
});

这篇关于我如何把“(全部)选择全部” SWT表头中的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆