Jan Hruby
Jan Hruby

Reputation: 1497

SWT TableCombo disable highlighting of selected item

I am using TableCombo and when I push the dropdown button, the list of all items is shown. I would like to achieve that currently selected row is not highlighted in this list (because I use different background colors depending on type of item and the highlight hides the background color of selected item). I have tried creating the table with SWT.NO_FOCUS and SWT.HIDE_SELECTION flags, but it did not remove the highlight. Any ideas?

I have tried to find out something like highlighter in swing, but I haven't succeed

Upvotes: 1

Views: 5305

Answers (2)

Campa
Campa

Reputation: 4495

As suggested in this SO answer, one could disable the event passed on to SWT.EraseItem:

table.addListener(SWT.EraseItem, new Listener() {   
    @Override
    public void handleEvent(Event event) {
        event.detail &= ~SWT.SELECTED;
    }
});

table is the SWT table I get from my JFace TableViewer. Not sure about the TableCombo API.

Upvotes: 0

Jan Hruby
Jan Hruby

Reputation: 1497

I just found this thread, which pretty much answers my question. For SWT.FULL_SELECTION highlighting is taken care of by OS automatically - see Table.CDDS_ITEMPOSTPAINT(NMLVCUSTOMDRAW nmcd, int wParam, int lParam) on Win32.

However this behavior can be modified by style constants. Correct solution for me was using SWT.FULL_SELECTION (whole row can be selected) and SWT.NO_FOCUS (dark blue highlight is not used) and SWT.HIDE_SELECTION (hides default gray background color for selected item) flags together.

Sadly, the HIDE_SELECTION flag is not supported by SWT Tree.

Upvotes: 1

Related Questions