0

我正在编写一个基于 Eclipse RCP 的应用程序,并试图在 ViewPart 上绘制一个矩形。但是,即使指定了边界,矩形似乎也占据了整个屏幕。以下是我的代码。

public void createPartControl(Composite parent) {
        Shell shell = parent.getShell();

        Canvas canvas = new Canvas(parent, SWT.NONE);
        LightweightSystem lws = new LightweightSystem(canvas);
        RectangleFigure rectangle = new RectangleFigure();
        rectangle.setBounds(new Rectangle(0, 0, 10, 10));
        rectangle.setBackgroundColor(ColorConstants.green);
        lws.setContents(rectangle);
}
4

1 回答 1

1

我没有使用过 Draw2D,但我尝试通过创建另一个矩形图形并将其添加到第一个图形来修改您的示例,然后出现了。IE

// from your code
rectangle.setBackgroundColor(ColorConstants.green);

// new code
RectangleFigure r2 = new RectangleFigure();
r2.setBounds(new Rectangle(0,0,10,10));
r2.setBackgroundColor(ColorConstants.blue);
rectangle.add(r2);

// back to your code
lws.setContents(rectangle);

对我来说它看起来不错——在全绿色画布的左上角有一个蓝色的小矩形。我猜您用作画布内容的图形默认情况下(并且可能是必要的)占据了整个画布。

于 2010-07-26T18:38:07.080 回答