user592704
user592704

Reputation: 3704

GWT - DecoratorPanel - dynamic background color

I wondering how to set background color for DecoratorPanel dynamically? All examples I could see just showing CSS static modification but I couldn't find any dynamic examples. If you have some helpful snippets please share

Upvotes: 2

Views: 5786

Answers (1)

Scott Bailey
Scott Bailey

Reputation: 363

For dynamically editing styles, you can use the Style object, reached via the underlying DOM Element. Something like the following should work:

DecoratorPanel panel = new DecoratorPanel();
panel.getElement().getStyle().setBackgroundColor("#000000");

Doing this will assign an inline style to your element in the DOM. You'll find methods for most properties on the Style object, with "setProperty(String, String)" available for your more rare style needs.

If you are only changing backgrounds between a few preset color, you may also consider simply changing a css class name on the panel. This gives you the benefit of keeping all background styling within css. You can do this via:

panel.addStyleName("css-class-name");

and panel.removeStyleName("css-class-name");

Upvotes: 4

Related Questions