SWT Canvas randomly expanding composite [message #847850] |
Tue, 17 April 2012 14:10  |
Eclipse User |
|
|
|
So I'm putting a text label and a canvas inside of a composite. In the canvas I want to draw a 20x20 circle.
What's weird is that every time I add the canvas to the composite wrapper, it expands the size of the composite vertically in an odd manner like so:

Why does it make it so tall?
When I remove the canvas, the composite shrinks appropriately.

public StationIndicator(String displayTxt, Composite parent){
this(parent);
wrapper = new Composite(parent, SWT.NONE);
wrapper.setLayout(new FillLayout() );
canvas = new Canvas(wrapper, SWT.NONE);
canvas.setBackground(parentz.getDisplay().getSystemColor(SWT.COLOR_GRAY));
label = new Label(wrapper, SWT.NONE);
label.setText(displayTxt);
currColor = parentz.getDisplay().getSystemColor(SWT.COLOR_GRAY);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
//Rectangle clientArea = canvas.getClientArea();
e.gc.setAntialias(SWT.ON);
e.gc.setBackground(parentz.getDisplay().getSystemColor(SWT.COLOR_BLACK));
e.gc.fillOval(0,0,20,20);
e.gc.setBackground(currColor);
e.gc.fillOval(2,2,16,16);
}
});
}
|
|
|
|
Re: SWT Canvas randomly expanding composite [message #848735 is a reply to message #848577] |
Wed, 18 April 2012 10:22  |
Eclipse User |
|
|
|
Yes, something like:
wrapper.setLayout(new GridLayout(2, false));
Canvas canvas = new Canvas(wrapper, SWT.NONE);
canvas.setLayoutData(new GridData(20,20));
Grant
On 4/18/2012 7:22 AM, Ludwig Moser wrote:
> afaik the default size for a canvas is 64x64px
> so you probably need to overwrite or set the preferred size (sorry i do
> not remember which one it is - but i think it was preferred...)
>
> next time please provide a small runnable example to test - thanks.
|
|
|
Powered by
FUDForum. Page generated in 0.11280 seconds