[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Canvas vs Composite Question....

Alrighty... with a little more perseverance, i've been able to get both the widgets and the border drawing at the same time on the canvas. The issue I was having seems to be tied to the use of a Layout. If I set the location/bounds of the widgets manually, then they draw as expected. But if I use a layout to manage them, then I only get the widgets. (No custom border) The paintControl method is still called, but no border is drawn.

As for using the Group box border, im just toying around with custom controls trying to get a feel for what i can do, and how. I wanted to know how to surround something with a custom frame or border.

So i seem to have a workaround, but it's not ideal (could be improved by placing the widgets on their on composite, then i'd only have to place a single control) Anyone know why the setting of a layout causes this behavior?


The exact code i'm playing with here is:

public class MyWidget extends Canvas {

	public MyWidget( Composite parent, int style ){
		super( parent, style );
		
		Label one = new Label( this, SWT.None );
		one.setText("One");
//		one.setLocation(10,10);
//		one.setBounds(10, 10, 100, 50);
		Label two = new Label( this, SWT.None );
		two.setText("Two");
		
		//setLayout( new FillLayout(SWT.VERTICAL) );
		
		addPaintListener( new PaintListener(){
			public void paintControl( PaintEvent e ){
				MyWidget.this.paintControl(e);
			}
		});
		
	}
	
	public void paintControl( PaintEvent e ){
		GC gc = e.gc;
		Point pt = this.getSize();
		gc.setLineWidth(2);
		gc.setLineStyle(SWT.LINE_DASH);
               gc.drawRectangle(1, 1, pt.x, pt.y);
	}
	
}