Ok, we can't get the component size... so, what can we do?

I’ve read a number of other posts where it is clearly said that it’s currently not possible to dynamically retrieve the size of a component, as it’s an operation performed by the JS tier on the client.

But those posts didn’t explain how to work around the problem. I need to know the size because I have a component rendering an image with a scroller, and it must be possible to programmatically set which part of the image should be rendered at the center of the component. Can you give me some hint, please? Thanks.

I can come up with at least three options:

  1. Use
    https://vaadin.com/directory#addon/css-tools
    - simple but maybe not flexible enough.
  2. Create your own client-side widget to manage the scrolling the way you want - slightly complex but extremely flexible.
  3. Use Window.executeJavascript to run some JavaScript that checks the size and applies the appropriate scrolling - ugly hack that might work (until the browser window is reloaded which causes the scrolling to be reset but doesn’t cause executeJavascript to be invoked again).