Community
Participate
Working Groups
Clicking on a grayed item in a Table with SWT.CHECK style changes its checked state. Grayed items should behave as disabled and should not change their checked state in response to a click. The following line in Table.WM_LBUTTONDOWN(int wParam, int lParam) and in Table.WM_KEYDOWN (int wParam, int lParam): item.setChecked (!item.getChecked (), true); should be changed to: if (!item.getGrayed()) item.setChecked (!item.getChecked (), true);
Gray checkboxes do not necessarily mean that the checkbox is disabled, but are usually used to show a "partial" selection. For an example of this, go to the Import - from File System wizard, select a directory to import from, and then un-check one of its children. The parent item's check box turns gray to indicate "most but not all of my children". Closing report since checking of gray checkboxes is behaving as intended.
How can I get the disabled behavior if grayed items are not disabled? Unfortunately the methods participating in checking/unchecking behavior are package protected and cannot be overriden.
You'll need to manage this in a selection listener, as shown in the snippet below. As a side note, it is still not advised to use setGrayed() to indicate a disabled checkbox because on gtk this draws as a partial selection (a horizontal line, not a gray checkbox), which would be very confusing to users. Perhaps "setPartialCheck()" would have been a more appropriate name than "setGrayed()". public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 200); final Table table = new Table(shell, SWT.CHECK); table.setBounds(10, 10, 170, 150); table.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (e.detail == SWT.CHECK) { TableItem item = (TableItem) e.item; if (item.getData() != null) { // disabled item.setChecked(!item.getChecked()); } } } }); for (int i = 0; i < 20; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText("item" + i); item.setChecked(i % 2 == 0); if (i % 3 == 0) { item.setText(item.getText() + " (disabled)"); item.setData("disabled"); } } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }