Converting Units or getting absolute vlaues in PIXELS

Is it possible to get the parent components units dimension as PIXEL no matter in what units it has been defined.

Lets assume that the component has been defined as 100% or undefined size.

//this what I currently found but it return 100. and getWidthUnit() returns 8 which probably corresponds to PERCENTAGE

float elementWith = mycomponent.getParent().getWidth();

I am looking for something like…

int pixelWidth = mycomponent.getParent().getAbsoluteWidth();
//in Pixel.

which I plan to call after a click event, therefore the server roundtrip will know about the actual parent size before creating the object constructor that must use the code.

In general, the computed sizes are not communicated back to the server in Vaadin. The window size is, though, and you can add a ResizeListener for it. See e.g.
this thread

What would be your use case where you would need to know the size in pixels explicitly, instead of letting the layouts take care of any dependent size adjustments etc?

Thanks for the answer.
The case would be as in populating a grid layout dynamically based on the client window size.

Let say that I want to add cards on a deck… the widest the deck (client window) the more cards I can place side by side.

Henri, the window size does not seem to be communicated to the server by Vaadin 7.1.6, until a resize. That is, on “setVisible(true)” there is no communication of the size, even if the window is marked as immediate.

Here is another example where knowing a component’s size in pixels would be really useful.

I have a Vaadin Chart rendered in a Panel, and a button to allow the user to generate and save a PNG version. Note that this is different from the standard Vaadin Charts client downloader. I am letting the user generate a file on the server so that it can be saved on the server. This way others (management) can access the chart at any time.

Anyway, I can use the SVGGenerator utility to create an svg version, then use Batik to create a PNG. Only problem is that the SVGGenerator will generate a 640x400 image, and in my test cases this truncates. I need to tell the SVGGenerator how big, in pixels, to generate to. I might use a resizelistener and try and force a resize somehow to get the size captured.

For anybody stumbling on this thread: see e.g. the
SizeReporter add-on