views:

22

answers:

1

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.

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.

A: 

You could use a FormLayout to allow stacking objects, then add a checkbox on top of the table as follows:

FormData fd = new FormData();
fd.left = new FormAttachment(table, 5, SWT.LEFT);
fd.top = new FormAttachment(table, 5, SWT.TOP);
checkbox.setLayoutData(fd);
checkbox.moveAbove(table);

You might find it useful for correctly aligning the checkbox to obtain the height of the table header row with table.getHeaderHeight().

Paul Lammertsma