Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Skins support and changing colours

Tuesday, September 23, 2003, 9:20:00 PM, Minh Chiem wrote:

> I'm trying to avoid writing a button widget, but I'm not sure how I'd go
> about getting a gc on a button.
>  From the snippets, this seems to be the only way I can change it.
>     button.addPaintListener(new PaintListener()
>       {
>          public void paintControl(PaintEvent e)
>          {
            
> e.gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
>          }
>       });

> but it doesn't work, and the color still stays grey.

That is the correct way to get a GC on the button.

The GC in SWT works much the same way as the Graphics class of AWT.
Just setting the color of the GC doesn't do anything.  You're
basically picking out a brush color when you do that, but you haven't
really used it.  You need to do a fillRectangle() of the widget's
bounds to actually see the color appear.  Note that you will want to
make the rectangle slightly smaller so you can see the widget's trim,
so the button appears to push, and you will want to repaint the button
when it's pressed in, shifting the rectangle appropriately.  You will
also need to use drawText() to draw the text on top of the rectangle
you just painted.

Please post future usage questions to the newsgroup.  The mailing list
is for the development of SWT.

David
-- 
Regards,
David                            
mailto:dlwhiteman@xxxxxxxxxxxxxxx



Back to the top