How do I get the height of a GWT object in pixels? I am trying to find a getHeight method or something similar..
You are probably looking for getOffsetHeight()
(inherited by every part of the UI from UiObject
):
Gets the object's offset height in pixels. This is the total height of the object, including decorations such as border, margin, and padding.
There's also the getClientHeight()
from Element
:
Returns the inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin.
You can access the underlying Element of every UiObject (meaning Widgets, etc) via the getElement()
method.
Be sure to check that the item is visible at the time the size is read, else you will get 0.
There is indeed getOffsetHeight() but that just gives the total height of the object, including decorations such as border and padding, but not margin.1 You can get the element and use getClientHeight() and it gives the inner height of an element in pixels, including padding but not the horizontal scrollbar height, border, or margin.
So getting the full rendered height including margins don't seem to be possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With