[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Canvas vs Composite Question....
|
In your use case I would use a Composite to put all your Label and Text
widgets in and then create a Canvas that does the border drawing via
painting (You could use a Composite too really, however, Canvas would be the
appropriate widget to subclass for drawing as you stated, and the Canvas API
states as well). As a Canvas is a subclass of Composite it can do all the
stuff a Composite can do, thus, you can put your original Composite
containing all your Labels/Text widgets onto the Canvas and draw your border
around it.
(By the way, I assume a Group-style border is not what you wanted, otherwise
you could just use a Group widget as your parent composite and get a border
around them.)
Hope that helps,
Regards,
Emil
"Kris Lyon" <kris.lyon@xxxxxxxxxx> wrote in message
news:4647486a00282874b880689dc134fbf2$1@xxxxxxxxxxxxxxxxxx
> 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... }
>
>
> }
>