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!
You can simulate a button using CLabel. Add a mouselistener to change the background on mouse down and mouse up, and in the mouse up event dispatch a selection listener event so that it behaves the same as a button. For example:
This briefly changes the background of the button while you are pressing the mouse to give the effect of clicking a button. CLabel can also be extended, unlike other SWT widgets, so you can create a subclass if you need to do this often.
On windows operating systems
button.setBackGround
doesn't work directly. A small snippet of code can help. Override the paint event of button as shown below:------obj is button name in below snippet------------
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.
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.
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.