仍在寻找解决方案
我有以下问题:我使用 SWTGC
将 GraphNodes 中包含的图形绘制到 Zest Graph 中。就 Linux 和 MacOS 而言,一切正常。但是当我在 Windows 上运行我的 jar 时,节点看起来很奇怪。颜色未正确绘制且没有透明度(通过 实现setAlpha()
)GC
。
这是两个屏幕截图来说明我的问题:
Linux:
视窗:
编辑:
我刚刚创建了这个工作的“迷你”示例来进行测试。如果有人有想法,为什么窗口上的矩形是黑色的,我将非常感谢您的回答。这是back.png
图像:
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.IContainer;
public class MiniExample
{
public static void main(String[] args)
{
Display display = Display.getDefault();
Shell shell = new Shell(display);
Graph graph = new Graph(shell, SWT.NONE);
graph.setSize(100, 100);
CustomFigure fig = new CustomFigure(new Label());
fig.setSize(-1, -1);
CustomNode node = new CustomNode(graph, SWT.NONE, fig);
node.setLocation(5, 5);
shell.pack();
shell.open();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
}
/* Minimal helper class for the figure */
static class CustomFigure extends Figure
{
private Image background = new Image(Display.getDefault(), "back.png");
private GC gcBack = new GC(background);
private Label all = new Label(background);
private Color blau = new Color(Display.getDefault(), 19, 59, 94);
public CustomFigure(Label label)
{
ToolbarLayout layout = new ToolbarLayout();
setLayoutManager(layout);
setMiddle(3);
add(all);
}
/* The problem has to occur somewhere here... */
public void setMiddle(int value)
{
gcBack.setBackground(blau);
gcBack.setForeground(blau);
gcBack.setAlpha(255);
/* color background blue and draw the nr of connections */
gcBack.drawRoundRectangle(6, 6, 15, 15, 3, 3);
gcBack.fillRoundRectangle(6, 6, 15, 15, 3, 3);
gcBack.setForeground(ColorConstants.white);
gcBack.drawText(value+"", 9, 6, true);
gcBack.setAlpha(255);
all.repaint();
}
}
/* Minimal helper class for the node */
static class CustomNode extends GraphNode
{
public CustomNode(IContainer graphModel, int style, CustomFigure figure)
{
super(graphModel, style, figure);
}
@Override
protected IFigure createFigureForModel()
{
return (IFigure) this.getData();
}
}
}