Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Cannot change background of Button ?
Cannot change background of Button ? [message #441023] Tue, 10 August 2004 08:13 Go to next message
Eclipse UserFriend
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 #441127 is a reply to message #441023] Tue, 10 August 2004 15:29 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
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 #441182 is a reply to message #441127] Wed, 11 August 2004 02:57 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Douglas Pollock is currently offline Douglas PollockFriend
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.
Previous Topic:KeyListeners and pressing two keys at the same time
Next Topic:SWT Browser & Mozilla
Goto Forum:
  


Current Time: Thu Apr 25 05:21:27 GMT 2024

Powered by FUDForum. Page generated in 0.03327 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top