Sub-window position problem (centering)

Hi,

I display a picture from a DB as an image (StreamResource) in a sub-window (popup).
Everything works except that the position of the sub-window moves after a slight delay.
I guess it has to do with the image size being calculated after the initial position and subsequently moved to a new when the size has been calculated.
Is there something I can do to prevent the window from showing until the size has been calculated?



final Image fullImage = new Image(“”, getComponentPicture(item)); // StreamResource
final Window subWindow = new Window();
Layout layout = new VerticalLayout();
subWindow.setContent(layout);
layout.addComponent(fullImage);

subWindow.center();
addWindow(subWindow);

You could try reading the image size on the server-side and using that to set the width and height of the Image component.

Thanks, I fixed the problem using ImageIO like this:



BufferedImage serverImage = ImageIO.read(new ByteArrayInputStream(imagebytes));
fullImage.setHeight(serverImage.getHeight(), Unit.PIXELS);
fullImage.setWidth(serverImage.getWidth(), Unit.PIXELS);