tags:

views:

55

answers:

1

Hi, any experience in changing a Widget's (background-) color dynamically? afaik I can only change the CSS style name but as the color is computed, I don't have a chance here?

I found something like DOM.setStyleAttribute(mywidget.getElement(), "background", "#FF0000"); but that rather looks nasty.

any ideas?

A: 

This is pretty much the standard way to do it. If you only need to change the background color you could create a function to do this for you:

public void setBgColor(String color)
{
    setStyleAttribute(this.getElement(), "background", color)
}

or if you want it to work with all widgets:

public void setBgColor(UIObject object, String color)
{
    setStyleAttribute(object.getElement(), "background", color);
}
Hannson