SWT TableCombo disable highlighting of selected item

邮差的信 提交于 2019-12-13 02:58:18

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11097428/swt-tablecombo-disable-highlighting-of-selected-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!