0

I am writing an Eclipse RCP-based application and am trying to draw a rectangle on top of a ViewPart. However, the rectangle seems to take up the whole screen even when specifiying the bounds. The following is my code.

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);
}
Ohanes Dadian
  • 625
  • 1
  • 9
  • 17

1 Answers1

1

I haven't used Draw2D, but I tried modifying your example by creating another rectangle figure and adding it to the first one, and that one shows up. I.e.

// 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);

It looks fine to me - there's a little blue rectangle in the top left corner of the totally green canvas. I guess that the figure you use as the contents of the canvas, by default (and probably by necessity), takes up the whole canvas.

Ladlestein
  • 6,100
  • 2
  • 37
  • 49
  • Thank you for your assistance, Ladlestein. You seem to be right. The first rectangle takes up the whole canvas, no matter what. – Ohanes Dadian Jul 26 '10 at 20:13