Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Canvas randomly expanding composite
SWT Canvas randomly expanding composite [message #847850] Tue, 17 April 2012 18:10 Go to next message
abadamcd1 abadamcd1 is currently offline abadamcd1 abadamcd1Friend
Messages: 40
Registered: December 2011
Member
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:
index.php/fa/7956/0/

Why does it make it so tall?

When I remove the canvas, the composite shrinks appropriately.
index.php/fa/7955/0/

	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 #848577 is a reply to message #847850] Wed, 18 April 2012 11:22 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
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.
Re: SWT Canvas randomly expanding composite [message #848735 is a reply to message #848577] Wed, 18 April 2012 14:22 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
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.
Previous Topic:how to embed swt shell into native window
Next Topic:SWT performance on drawing text (compare with Swing, sample code provided)
Goto Forum:
  


Current Time: Thu Apr 25 08:40:52 GMT 2024

Powered by FUDForum. Page generated in 0.04267 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top