Select swt表格更改选择项颜色

Select swt表格更改选择项颜色,select,swt,selection,Select,Swt,Selection,我使用的是一个标准的swt表,您可能知道,当选择一个项目时,默认情况下它是蓝色的(windows标准)。当选择处于非活动状态时,它将变为浅灰色。我想覆盖这两种颜色。。。我已经在网上搜索过了,但只能找到一些非常旧的代码,这些代码似乎不再适用于table小部件 下面是一些示例代码,我试图覆盖默认颜色,但它似乎不起作用(请原谅这些脏代码,我只是想让一些东西起作用): 如果您想使用TableViewer来管理表格,您可以使用StyledCellLabelProvider来确定各个单元格的颜色/字体等。T

我使用的是一个标准的swt表,您可能知道,当选择一个项目时,默认情况下它是蓝色的(windows标准)。当选择处于非活动状态时,它将变为浅灰色。我想覆盖这两种颜色。。。我已经在网上搜索过了,但只能找到一些非常旧的代码,这些代码似乎不再适用于table小部件

下面是一些示例代码,我试图覆盖默认颜色,但它似乎不起作用(请原谅这些脏代码,我只是想让一些东西起作用):


如果您想使用TableViewer来管理表格,您可以使用StyledCellLabelProvider来确定各个单元格的颜色/字体等。TableViewer将为您处理“所有者绘制”方面的问题。最大的麻烦是设置TableViewer附带的ContentProvider、LabelProvider和输入类。

更多:子类StyledCellLabelProvider,重写更新(ViewerCell)方法,使用ViewerCell.getElement()获取行元素,适当调用cell.setText(),并设置单元格的颜色。
    table.addSelectionListener(new SelectionListener() {
            @Override
            public void widgetSelected(SelectionEvent event) {
            Color rowSelectionColor = 
                            new Color(Display.getCurrent(),new RGB(235, 200, 211));
                            TableItem item =(TableItem)event.item;
                item.setBackground(0,rowSelectionColor);
                item.setBackground(1,rowSelectionColor);
                item.setBackground(2,rowSelectionColor);


            }

            @Override
            public void widgetDefaultSelected(SelectionEvent event) {
            Color rowSelectionColor = 
                            new Color(Display.getCurrent(),new RGB(235, 200, 211));
                            TableItem item =(TableItem)event.item;
                item.setBackground(0,rowSelectionColor);
                item.setBackground(1,rowSelectionColor);
                item.setBackground(2,rowSelectionColor);


            }
        });