[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Canvas vs Composite Question....
|
- From: kris.lyon@xxxxxxxxxx (Kris Lyon)
- Date: Wed, 30 Apr 2008 23:02:25 +0000 (UTC)
- Newsgroups: eclipse.platform.swt
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
I'm just starting out doing some custom control development and I'm
running into what I hope is a simple problem. From what I've read, I'm
fairly certain that I understand the situations where you should subclass
Composite vs Canvas.
For example:
I would like to make a composite control made up of existing swt widgets,
say a few labels and text boxes, however I'd like to surround them with a
custom border.
If I subclass Canvas, im not sure how have the widgets display themselves
on the canvas.
If I subclass Composite (which I believe is the right way to go) I can
either have the controls draw themselves, OR draw the border. It seems
that if I set the layout on the Control the widgets that have been added
to the custom control will display, but the paintListener (which draws my
border on the composite) doesn't fire. If no layout is set on the
control, the widgets don't display, but the paintListener fires and the
border is displayed fine.
I'm working from memory here, so I apologize in advance for any obvious
programming errors...
Any help would be appreciated...
-k
public class MyWidget extends Composite {
public MyWidget( Composite parent, int style ){
super( parent, style );
Label first = new Label( this, SWT.NONE );
first.setText("One");
Label second = new Label( this, SWT.NONE );
second.setText("Two");
// If this line is commented out my paintControl method will be called
and
// I see only my custom rectangular border.
//
// If left un-commented, I see my widgets (labels) but no border.
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;
// Draw my custom border surrounding both labels here...
}
}