When I needed to add or modify a CSS property of an element in Google Web Toolkit (GWT), I’d always do it like this :
widget.getElement().setAttribute("style", "align:right;"); |
However, if there was already any style information for defined for that element, it would be overwritten. You could get the current attributes first and then readd them along with your new info but there is a much cleaner way :
widget.getElement().getStyle().setProperty("align", "right"); |
Important! Note that when setting a style property, your need to use camel case for the property name.
//WRONG! myWidget.getElement().getStyle().setProperty("background-color", "red"); // RIGHT myWidget.getElement().getStyle().setProperty("backgroundColor", "red"); |