Problem in auto resizing window

Hi,
I am trying to manage the size of a window according to the content.
Everything is fine for the first time that the window is displayed, but for consequent changes the window is not resized until the page is refreshed.

Step 1: Window fits the content

Step 2: Content is changed

Step 3: Refresh is hit, now looks better

Here is my code:


import com.itmill.toolkit.Application;
import com.itmill.toolkit.terminal.Sizeable;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;

public class WindowAutoResize extends Application
{
    Window main = new Window("Main Window");
    Window child = new Window("Child Window");
    Label shortText = new Label("This is a fairly short text");
    Label longText = new Label("This is a veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery long text");
    Integer counter = 1;

    public WindowAutoResize()
    {
        shortText.setWidth(-1, Sizeable.UNITS_PIXELS);
        longText.setWidth(-1, Sizeable.UNITS_PIXELS);
        child.setSizeUndefined();
        child.getLayout().setSizeUndefined();
        child.addComponent(new Button("Change", new ChangeWindowListener()));
        child.addComponent(shortText);
    }
    
    @Override
    public void init()
    {
        setMainWindow(main);
        main.addWindow(child);
    }
    
    private class ChangeWindowListener implements Button.ClickListener
    {
        public void buttonClick(ClickEvent event)
        {
            child.removeComponent(shortText);
            child.removeComponent(longText);
            if (counter++ % 2 == 1)
                child.addComponent(longText);
            else
                child.addComponent(shortText);
            child.requestRepaintAll();
            main.requestRepaintAll();
        }
    }
}

Is there any means by which I can have this window resized every time its content changes?
Thanks,
Houman.

Is there anyone who can comment on this problem?
:frowning: :?:

Should the window size really change each time the contents change? I have not seen anything like this in any other framework…

Hi, and sorry for the late input.

I see the need for this type of funtionality, but I guess it should be somehow optional: sometimes it is exactly the thing you don’t want.

I see you have already tried the “requestRepaintAll”, and it doesn’t help.

Could you please create a ticket for this in our
Trac
, thanks!

Jouni:
Thanks, I will create a ticket for this.

Anonymous:
Actually this is a feature achieved with a special settings applied on the layouts.
This is exactly what happens if you don’t specify size on an HTML tag.

Ticket created: http://dev.itmill.com/ticket/2865