tags:

views:

3188

answers:

3

This is pretty simple, I come from a swing/awt background.

I'm just wondering what the proper way to set the background color for a SWT widget is?

I've been trying:

widget.setBackGround( );

Except I have no idea how to create the color Object in SWT?

Thanks, Brian Gianforcaro

+7  A: 

To create a color, try this:

Device device = Display.getCurrent ();
Color red = new Color (device, 255, 0, 0);
jodonnell
That worked. Thanks, your the man. I just couldn't find where to get current device from.
Brian Gianforcaro
Make sure you don't forget to dispose of this Color! Otherwise you will leak native resources.
Eddie
+4  A: 

Remember that in SWT you must explicitly dispose any resources that you create when you are done with them. This includes widgets, fonts, colors, images, displays, printers, and GCs. If you do not dispose these resources, eventually your application will reach the resource limit of your operating system and the application will cease to run.

See also: SWT: Managing Operating System Resources

qualidafial
+10  A: 
qualidafial
This should be your standard for any color supported in the SWT.COLOR_* set. As stated, you do not need to remember to dispose of colors created in this fashion.
James Van Huis