Glyn Glyn - 7 months ago 43
Java Question

GWT Java - set font style

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);

Answer

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.