问题描述
我使用的是标准的swt表,您可能知道,默认情况下,选中某项时,其颜色为蓝色(Windows标准).当该选项处于非活动状态时,它将变为浅灰色.我想覆盖这两种颜色...我在网上搜索了所有内容,但只能找到一些非常旧的代码,这些代码似乎不再适用于表格小部件.
I'm using a standard swt table which, as you may know, by default when an item is selected is colored blue (windows standard). When the selection is inactive, it turns light gray. I would like to override both colors... I've searched all over the web but could only find some very old code which no longer seems to work with the table widget.
下面是一些示例代码,我试图覆盖默认颜色,但它似乎不起作用(请原谅脏代码,只是想使某些事情起作用):
Below is some sample code I was trying to overwrite the default color but it doesn't seem to be working (please excuse the dirty code, was just trying to get something to work):
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);
}
});
任何想法都会得到极大的赞赏:D
Any ideas would be greaaatly massively appreciated :D
推荐答案
如果要使用TableViewer来管理表,则可以使用StyledCellLabelProvider确定单个单元格的颜色/字体/等. TableViewer将为您处理所有者抽奖"方面.最大的麻烦是设置与TableViewer一起提供的ContentProvider,LabelProvider和输入类.
If you want to go with a TableViewer to manage your table, you can use a StyledCellLabelProvider to determine the colors/fonts/etc for individual cells. The TableViewer will take care of the "owner draw" aspects for you. The biggest hassle is setting up the ContentProvider, LabelProvider, and input classes that go with the TableViewer.
这篇关于swt表变更选择项目颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!