gpt4 book ai didi

Eclipse:表列图像是否透明?

转载 作者:行者123 更新时间:2023-12-02 06:45:23 25 4
gpt4 key购买 nike

一旦我开始在 Eclipse 表格单元格中绘制自己的图像,突出显示该表格单元格就会产生奇怪的突出显示颜色。亲自看看:

alt text

虽然透明度实际上像第一列中一样保留,但突出显示蓝色并不像应有的那样蓝色。这是我的错还是 Eclipse 的错?

这是代码片段:

public class TransparentOrNot {

public static void main(String[] args) {
Display firstDisplay = new Display();
Shell firstShell = new Shell(firstDisplay);
firstShell.setText("Transparent-or-not!");
firstShell.setSize(300, 200);
firstShell.setLayout(new FillLayout());

TableViewer viewer = new TableViewer(firstShell, SWT.MULTI);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);

TableViewerColumn tableViewerColumn = new TableViewerColumn(viewer, SWT.CENTER);
tableViewerColumn.getColumn().setText("First");
tableViewerColumn.getColumn().setWidth(150);
tableViewerColumn.setLabelProvider(new ColumnLabelProvider() {

@Override
public Image getImage(Object element) {
return ImageDescriptor.createFromFile(TransparentOrNot.class, "/red.png").createImage();
}

@Override
public String getText(Object element) {
return null;
}
});
tableViewerColumn = new TableViewerColumn(viewer, SWT.CENTER);
tableViewerColumn.getColumn().setText("Second");
tableViewerColumn.getColumn().setWidth(150);
tableViewerColumn.setLabelProvider(new CenterImageLabelProvider());
viewer.setContentProvider(ArrayContentProvider.getInstance());

viewer.setInput(new String[][]{{"a", "b"}, {"c", "d"}});

firstShell.open();
while (!firstShell.isDisposed()) {
if (!firstDisplay.readAndDispatch()) {
firstDisplay.sleep();
}
}
firstDisplay.dispose();
}

static class CenterImageLabelProvider extends OwnerDrawLabelProvider {

@Override
protected void measure(Event event, Object element) {
// no-op
}

@Override
protected void paint(Event event, Object element) {

Image image = ImageDescriptor.createFromFile(TransparentOrNot.class, "/green.png").createImage();

Widget item = event.item;
Rectangle bounds = ((TableItem) item).getBounds(event.index);

Rectangle imgBounds = image.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;

int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;

event.gc.drawImage(image, x, y);
}
}
}

最佳答案

重写erase()并且调用super.erase()有帮助。

关于Eclipse:表列图像是否透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1954834/

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