Thursday, 19 July 2007

Eclipse SWT: Disabling selection event in a Table

Sometimes we do not want users to be able to select cells or rows in the tables, but the standard styles for SWT Table widget do not give a NOSELECTION option.

This, however, can be easily achieved by masking the selection event, Just use the following piece of code for creating your tables:
final Table table = new Table(group, SWT.SINGLE | SWT.BORDER);
table.addListener(SWT.EraseItem, new Listener() {
public void handleEvent(Event event) {
if((event.detail & SWT.SELECTED) != 0 ){
event.detail &= ~SWT.SELECTED;
}
}
});

7 comments:

Anonymous said...

It doesn't work.
My rows remain selected...

Are you sure?

Anonymous said...

It works!! Thanks a lot !:)

Unknown said...

does not work in unix. Any other way to accomplish this?

Anonymous said...

It works on linux! Bless u! :)

pittsburgh pa hotels downtown said...

Wooow! I did a search on the topic and found many people will agree with your blog. Thank you for all that you do..

Anonymous said...

not working in mac os

Anonymous said...

please suggest if anything for mac