Reputation: 6531
I am subclassing the Canvas in SWT, and calling pack() inside of the constructor, the Canvas' size is computed as 64x64.
There is no Style or layout inside of my class.
this.setSize()
doesn't work.
public MyClass(Composite parent, int style) {
super(parent, SWT.NONE);
this.setBackground(getDisplay().getSystemColor(SWT.COLOR_YELLOW));
this.computeSize(1000, 1000, true);
this.pack();
Point s = this.getSize();
System.out.println(s.x); //prints 64
}
Upvotes: 1
Views: 3276
Reputation: 671
If you are subclassing Canvas then you can also override the computeSize method to force specific element sizes. This can be useful to make other elements flow around a fixed size component without having to use the layout hints, or if you want to make the canvas size set based on say an image that it's rendering.
This might be something like this in your MyCanvas class:
public Point computeSize (int widthHint, int heightHint, boolean changed) {
Point initialSize = super.computeSize (widthHint, heightHint, changed);
initialSize.x = 1000;
initialSize.y = 1000;
return initialSize;
}
Upvotes: 3
Reputation: 21
Have you tried hinting the desided size via GridData
?
final GridData data = new GridData();
data.widthHint = 1000;
data.heightHint = 1000;
canvas.setLayoutData(data);
Upvotes: 2
Reputation: 382160
You don't give yourself the size : it is given by the layout of the component using your MyClass.
So your canvas should be ready to handle any size.
Upvotes: 2