开发者

SWT/JFace: disabled checkbox in a table column

It is quiet easy to create a Table with a checkbox column, e.g., using the SWT.CHECK flag. But how to make checkboxes in certain 开发者_如何学运维table rows not editable while those in other rows remain editable?


I don't know a simple way of doing that.

But I see two possible solutions: There is a JFace Snippet doing a rather extreme hack to emulate natively looking checkboxes in tables with images here.

And then you could put own checkboxes into a plain Table, like this. That way you can control the state of every checkbox on your own.

I'd go with the 2nd solution.


try this:

table.addListener(SWT.Selection, new Listener() {
   public void handleEvent(Event event) {
       if( event.detail == SWT.CHECK ) {
           event.detail = SWT.NONE;
           event.type   = SWT.None;
           event.doIt   = false;
           ((TableItem)event.item).setChecked(false);
       }
   }
});


I had faced a similar problem and i was able to solve it in the table using SWT.check. In the widgetSelected Event of the table you can try the following code:

TableItem[] item = table.getItems();

for(int j=0; j<item.length;j++)
        {
            TableItem tblItem = item[j];
            if (tblItem.getChecked())
            {
                table.setSelection(j);
                 if(codition for the checkbox to be non-Editable written here)
                 {
                     item[table.getSelectionIndex()].setChecked(false);
                 }
            }
        }

In the above code after the table has been filled and when the user tries to check any item in the table the above code should be called. When the checkbox is clicked if the condition meets for the checkBox to be non-editable the checkbox is not selected otherwise it is selected.In this way in a table certain rows can be editable while others will be non-editable according to the required conditon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜