gpt4 book ai didi

swt - Eclipse OwnerDrawLabelProvider 使选择背景为深蓝色

转载 作者:行者123 更新时间:2023-12-01 11:36:36 26 4
gpt4 key购买 nike

我目前正在开发 Eclipse RCP 应用程序,并且需要使用 OwnerDrawLabelProvider作为 TableViewerColumnCellLabelProvider这是因为当我使用任何其他 CellLabelProvider 时,使用的图像没有居中。

My problem is that when the row is selected, the background of the cell that has this provider is of a darker blue than all the other cells.

这是“选中”状态的样子:

enter image description here

这是我的 OwnerDrawLabelProvider:

class SomeLabelProvider extends OwnerDrawLabelProvider {
private static final int smallColumnSize = 70;

@Override
protected void measure( Event event, Object element ) {
Rectangle rectangle = IMAGE_CHECKED.getBounds();
event.setBounds( new Rectangle( event.x, event.y, smallColumnSize,
rectangle.height ) );
}

@Override
protected void paint( Event event, Object element ) {
Rectangle bounds = event.getBounds();
//paint icon at the center
event.gc.drawImage( getImage( element ),
bounds.x + ((smallColumnSize -
IMAGE_CHECKED.getBounds().width) / 2),
bounds.y );
}

//this is implemented somewhere else
protected abstract Image getImage( Object element );

}

提前致谢!

最佳答案

这是由默认的 erase 方法引起的,JavaDoc 说:

Handle the erase event. The default implementation colors the background of selected areas with SWT.COLOR_LIST_SELECTION and foregrounds with SWT.COLOR_LIST_SELECTION_TEXT. Note that this implementation causes non-native behavior on some platforms. Subclasses should override this method and not call the super implementation.

所以只需添加一个什么都不做的erase覆盖:

@Override
protected void erase(Event event, Object element)
{
// Don't call super to avoid selection draw
}

关于swt - Eclipse OwnerDrawLabelProvider 使选择背景为深蓝色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26463520/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com