tags:

views:

77

answers:

2

Right now I am trying to change the background color of a org.eclipse.swt.widgets.Button with the following code:

    Button sceneButton = new Button(border, SWT.TOGGLE | SWT.FLAT);  
    sceneButton.setBackground(Color.RED);

This works fine when I run the program in Solaris, but does nothing when I run the code in Windows. Is this possible? If not, is there some kind of workaround that would allow me to change the background color (even if the "color" is an image) while still displaying text in the button? Thanks!

+1  A: 

You can't. In the documentation of method Control.setBackground(), it is mentioned:

For example, on Windows the background of a Button cannot be changed.

True Soft
I read that before posting and realized it was probably impossible. I was just wondering if anyone has had this problem/has come up with some kind of workaround, even if said workaround is incredibly hacky.
Dorrene Brown
Maybe a Label with an Image of a button colored with the color you want. And an extra image when you 'click' the button.
True Soft
We just opted to place a BackgroundImage onto the button, which colored the area in between the button and the button's border. Alternatively, we could have used the SWT_AWT Bridge and integrated SWT buttons into the GUI, but that would have been overly complicated and would have taken too much time. Thanks!
Dorrene Brown
A: 

The background of a button in Windows is set from outside of SWT.

Right-click your desktop, click Properties.

Go to the "Appearance" tab.

Click "Advanced".

I believe "3D objects" determines the button background. This is determined by each user's theme.

alt text

One great thing about SWT is it uses the underlying system widgets and themes. A frustrating thing about SWT is it uses the underlying system widgets and themes.

Zoot
Unfortunately, this program is running on both Solaris and Windows, and the behaviors need to be as similar as possible.
Dorrene Brown
A frustratingly large amount of Windows color is controlled by the system theme. I wish you luck with your project.
Zoot