Reputation: 2005
I want to set the label style depending on certain input. I have found how to set the colour, font weight, font style, font size and indent. However, I can not find how to set the font family to, e.g., "Arial".
lblTaskName.getElement().getStyle().setColor("Navy");
lblTaskName.getElement().getStyle().setFontWeight(FontWeight.BOLD);
lblTaskName.getElement().getStyle().setFontStyle(FontStyle.ITALIC);
lblTaskName.getElement().getStyle().setFontSize(14.0, Unit.PT);
lblTaskName.getElement().getStyle().setTextIndent(15.0, Unit.PT);
Upvotes: 2
Views: 2205
Reputation: 41099
If you are changing so many properties, I would recommend defining a class in your CSS and applying this class to the label.
myWidget.addStyleName("label");
It's a much cleaner approach than hardcoding all values in your code. For example, you can add rules to your CSS file to adjust these properties based on a screen size, and you won't have to touch your code.
Upvotes: 0
Reputation: 16099
I've seen issue withWidget#getElement()#setAttribute()
in IE.
The better way is:
myWidget.getElement().getStyle().setProperty("fontFamily", "Arial");
I've never tried font-family in this way. The general rule for getStyle().setProperty('camelCase','value')
camel-case
becomes -> camelCase
.
Upvotes: 3