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;
}
}
});

6 comments:

Gamby said...

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

Are you sure?

Anonymous said...

It works!! Thanks a lot !:)

gfh said...

The World Leading wow power leveling and wow gold wow power leveling

Generic Viagra said...

I was trying to do this for a long because there's many users in my blog that just post bad things on it.

mericano1 said...

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

Anonymous said...

It works on linux! Bless u! :)