[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Custom Widget question

Oops - sorry, Philipp.
Yep, Tom is right. I should compile these things before posting them <g>.
It should be:
    MyScrolledComposite(Composite parent, int style) {
        super(widgetParent(parent, style),style);
    }

    static Composite widgetParent(Composite parent, int style) {
        Composite widgetParent = new Composite(parent,style);
        canvas header = new Canvas(widgetParent);
        ...
        return widgetParent
    }

This is a little Java trick that people use to get around the "don't call 
anything before the super" constraint.
Yep, it's exactly the same code... but it works because the compiler allows 
it <grin>.
We use it in a lot of our widget constructors to check that the style bits 
are valid for the control being constructed.
We also use it here and there to make sure a parameter passed to a 
constructor isn't null.

By the way, you might not want to pass the same style to both widgetParent 
and myScrolledComposite.
If someone passes in SWT.BORDER, for example, then you'd get 2 borders. You 
might want to decide who should get the style.

Good luck,
Carolyn

"Tom Schindl" <tom.schindl@xxxxxxxxxxxxxxx> wrote in message 
news:fr8d8k$k8k$1@xxxxxxxxxxxxxxxxxxxx
> Carolyn forgot to add the static to this method.
>
> Tom
>
> P.Simon schrieb:
>> okay that was a fast test. I already wondered why calling a method there 
>> would work while it would not do anything different then putting the 
>> lines before the super call and actually it also does not work this way. 
>> "Cannot refer to an instance method while explicitly invoking a 
>> constructor" it says :).
>>
>> So we are back to the beginning :).
>>
>>
>
>
> -- 
> B e s t S o l u t i o n . at
> --------------------------------------------------------------------
> Tom Schindl                                          JFace-Committer
> --------------------------------------------------------------------