Reputation: 587
I'd like to be able to access the font size of a GWT Label. I've tried:
String fontSize = label.getElement().getStyle().getFontSize()
but this seems to only be for font sizes that have been programatically set (and not font sizes that are decided by CSS rules). Any ideas?
Thanks,
~Owen
Upvotes: 4
Views: 1399
Reputation: 3048
If it is the computed size you are looking for, GWT does not provide it out of the box, but you should be able to use a simple JSNI
to retrieve it. Something like:
public static native String getComputedStyleProperty(Element element, String property) /*-{
if ($doc.defaultView && $doc.defaultView.getComputedStyle) {
return $doc.defaultView.getComputedStyle(element, null).getPropertyValue(property);
}
return "";
}-*/;
Untested but should get you started. Do note that, the property
should be camelCase
and, for IE < 9, you should also check for currentStyle
. Also a fallback based on element
's style property should be returned, instead the empty string.
See also Get computed font size for DOM element in JS.
Upvotes: 2
Reputation: 121998
No, getFontSize() returns CSS property only
.
Give a try like below:
String fontsize= DOM.getStyleAttribute(label.getElement(), "font-size");
Upvotes: 0