Window and external image embedded autosize behavior in 5.3

Hi,
it seems today is a rich day for layout questions :slight_smile:

In 5.2, when a new Window constructed with the only embedded component inside, which is referencing external image, this window was automatically adjusted it’s size once image is loaded - both width and height was adjusted to image dimensions.

In 5.3 the height is autoset to image height, but the width seems to be equal to window caption and does not adjust when image is loaded, so image looks truncated.

I tried to setWidth(null) for the window but this did not help.

Is my current code correct for 5.3 ?


       Window zoom = new Window ( TM.get("order.zoom.title") );

        zoom.setModal ( true );
        zoom.addComponent ( new Embedded ( "", getOrderPreviewResource () ) );
        zoom.setVisible ( true );
        zoom.setResizable ( false );

        parent.addWindow ( zoom );
        zoom.setPositionY ( 200 );
        zoom.setPositionY ( 40 );

Thanks,
Dmitri

Hi!

The layout (VerticalLayout) has 100% width by default making it respect the caption width. Use window.getLayout().setSizeUndefined() and it should work.

100% for windows layout is a good default in case one defines the width, but usually this is not the case.

It is a know know inconvenience in our current layout system. To get rid of this we’d need to split Windows and sub windows to be different classes and add some logic to detect default layout, but I’m afraid we have to live this this for a moment now.

cheers,
matti

Hm, setSizeUndefined() did not help, window is still caption-wide and there is a horizontal scrollbar to scroll the rest of image width.

Still cannot get autoresize working properly with 5.3, maybe something will make a fresh look and give me glue what is wrong in the following code ?

Actually, I want to open a new modal window with a small image to preview. The window size should be automatically expanded to fit image size. It was working properly in 5.2 but no luck with 5.3 - window’s width is fixed to width of window’s caption, while the height is correctly adjusted by the height of an image:


private void enlargeImage ()
    {
        Window zoom = new Window ( "Image Preview" );
        zoom.setSizeUndefined ();

        Embedded imagePreview = new Embedded ( "", parent.getOrderPreviewResource () );
        imagePreview.setSizeUndefined ();

        zoom.addComponent ( imagePreview );
        zoom.setModal ( true );
        zoom.setResizable ( false );

        zoom.addListener ( new Window.CloseListener()
        {
            public void windowClose ( Window.CloseEvent closeEvent )
            {
                parent.removeWindow ( closeEvent.getWindow () );
            }
        } );

        parent.addWindow ( zoom );
    }

Thanks,
Dmitri

I tested this myself, and I can confirm the issue. The window width is not affected by the embedded as expected, even if you insert
Window.getLayout().setSizeUndefined()
in there.

The size is calculated correctly if you use a long Label instead of an image. So I think the bug is caused by a faulty onload-event handler on the Embedded.

Dimitri, could you file in a bug report for this? Thanks!

Hi Jouni, thanks, I filed a ticket -
http://dev.itmill.com/ticket/2738

Is this really fixed in Vaadin 6.3.4 because I can reproduce this issue ?

*** EDIT ***

I managed to do autosize the modal correctly with the following :


Window imageModal = new Window();
imageModal.setModal(true);
[b]
imageModal.getContent().setSizeUndefined();
[/b]
Embedded emb = new Embedded(null, new ExternalResource(res.getDocumentUrl()));
emb.setSizeUndefined();
imageModal.addComponent(emb);

bye !

Works for me with Vaadin 6.4, at least. Note that the example above is missing the line “zoom.getContent().setSizeUndefined();”.

If you can reproduce this with that correction, please post sample code demonstrating the issue, and indicate with which browser versions you see the issue.