Cannot change background of Button ? [message #441023] |
Tue, 10 August 2004 08:13 |
Eclipse User |
|
|
|
Originally posted by: pankajatncst.rediffmail.com
Hi
How can I change the background of a button in SWT ? I tried
button.setBackground(Color), but that does not work. Any other way to do
this ?
Thanks
Pankaj
|
|
|
|
Re: Cannot change background of Button ? [message #441182 is a reply to message #441127] |
Wed, 11 August 2004 02:57 |
Eclipse User |
|
|
|
Originally posted by: pankajatncst.rediffmail.com
Well, since it cannot be done directly, here's a workaround :
Image buttonImage = new Image(display, 50, 16);
Color currentColor = new Color(display, 255, 0 ,0);
GC gc = new GC(buttonImage);
gc.setBackground(currentColor);
gc.fillRectangle(buttonImage.getBounds());
gc.dispose();
Button colorButton = new Button(shell, SWT.PUSH);
colorButton.setImage(buttonImage);
This works !!
P.S. Don't forget the dispose the Image & Color when your done ;)
Pankaj
Steve Northover wrote:
> This is not supported on Windows. A C program can't do it either.
> "Pankaj Bhatnagar" <pankajatncst@rediffmail.com> wrote in message
> news:cfa03h$3oc$1@eclipse.org...
> > Hi
> >
> > How can I change the background of a button in SWT ? I tried
> > button.setBackground(Color), but that does not work. Any other way to do
> > this ?
> >
> > Thanks
> > Pankaj
> >
|
|
|
Re: Cannot change background of Button ? [message #441514 is a reply to message #441182] |
Mon, 16 August 2004 18:13 |
Douglas Pollock Messages: 84 Registered: July 2009 |
Member |
|
|
Pankaj Bhatnagar wrote:
> Well, since it cannot be done directly, here's a workaround :
>
> Image buttonImage = new Image(display, 50, 16);
> Color currentColor = new Color(display, 255, 0 ,0);
> GC gc = new GC(buttonImage);
> gc.setBackground(currentColor);
> gc.fillRectangle(buttonImage.getBounds());
> gc.dispose();
> Button colorButton = new Button(shell, SWT.PUSH);
> colorButton.setImage(buttonImage);
>
> This works !!
Does this work on GTK+ (or other widget tool kits)? What happens if the
widget theme specifies rounded buttons?
cheers,
d.
|
|
|
Powered by
FUDForum. Page generated in 0.03327 seconds