Bad window size with setSizeFull

Hello,

I have a dialog window that takes a component as an argument. If the component is expandable (i.e. component.setSizeFull() was invoked on it), I want the dialog’s layout to have setSizeFull() so that when the window is resized the layout resizes both horizontally and vertically. Otherwise, it only resizes horizontally. However, this results in a poor initial size for the dialog (see screen_shot_2). Without setSizeFull(), the dialog has a nice default size (see screen_shot_1). To get a decent initial size, I have to set a defined window size for the dialog. For example:

        dialog.setHeight(50, Unit.PERCENTAGE);
        dialog.setWidth(50, Unit.PERCENTAGE);

This is not an ideal solution because I’m dealing with an arbitrary component. For some components it makes for a bad initial size. I want to be able to call setSizeFull() on the layout without having to set a height/width in the dialog, so that it displays with the nice initial size. Is there a way to get what I want?

I’ve attached a sample program that demonstrates the problem. I’m using Vaadin 7.3.6.

This produces a nice initial size, but the component (a text area) is not vertically resizable:
http://localhost:8080/MyVaadin7Project/?expandable=false&set_height=false

This produces a poor initial size, but the component is vertically resizable:
http://localhost:8080/MyVaadin7Project/?expandable=true&set_height=false

This produces a better, but not optimal initial size, but the component is vertically resizable:
http://localhost:8080/MyVaadin7Project/?expandable=true&set_height=true

17541.jpg
17542.java (1.46 KB)
17543.jpg
17544.jpg
17545.java (961 Bytes)

Correct me if I’m wrong, but what I understood is that you want the dialogue to depend on the height of the child, and the child to depend on the height of the dialogue?

If your child is expandable (relative height), it needs to know the size of a parent. In this case, you need to set the height of the dialogue. If the child isn’t expendable, and has its own height, the dialogue can adjust itself accordingly by setting the height to undefined (dialogue.setHeight(null), same to the layout).

In your case neither the child or parent would know their height, since the child asks the parent, and the parent needs the child to know it’s size. The best you can do is to check what height has been defined for the child, and decide the dialogue height based on that.

Correct me if I’m wrong, but what I understood is that you want the dialogue to depend on the height of the child, and the >child to depend on the height of the dialogue?

Thanks for the reply.

I think what you describe is the scenario in section 6.13.1 of the Book of Vaadin on page 251. My understanding is that this applies if the parent is a layout, and the child has 100% height (i.e. the child’s height depends on its parent’s height), and the parent’s height is undefined (i.e. the parent’s height depends on its child’s height).

First, I’d like to point out the sample code I provided shows that a TextArea with 100% height inside a Layout with undefined height inside a window with undefined size actually works quite nicely.

But this is not quite the case here. The setup is a TextArea inside a VerticalLayout inside a Window. I want the TextArea and the VerticalLayout to have 100% height, and the Window to have undefined size.

I expect Vaadin to calculate a nice initial window size. It already does fine if the TextArea, VerticalLayout, and Window have undefined height. But If I set the TextArea and VerticalLayout to 100% height, then the initial window size is poor. My argument is that Vaadin should handle this scenario better.

By setting the height of the textarea and layout, you are effectively telling Vaadin that it shouldn’t use a default height. When the textarea is undefined, Vaadin reverts to it’s defaults; the textarea in particular has a predefined default width and height. Unfortunately, window does not; it always requires the user to either:

  1. have only undefined-sized components inside, or
  2. set a size for the window.

You are correct in that having the window being that small by default isn’t a visually pleasing thing; but it is consistent with how all other layouts in Vaadin work. None of them will give you a predefined default size in the same situation, they will all shrink. It is a concious design decision on our part, that works in all of our use cases.

For your particular application, you will need to decide your own defaults and implement them in your Window subclass. Since you already know if the component should be expanded, you can set your own default size if that boolean is false. It will also give you a more consistent visual look if all windows are (by default) the same size.

By setting the height of the textarea and layout, you are effectively telling Vaadin that it shouldn’t use a default height. >When the textarea is undefined, Vaadin reverts to it’s defaults;

OK. But when I set the height of the textarea to 100%, I don’t believe I’m telling Vaadin that it shouldn’t use a default height: I’m telling Vaadin that I’ll use 100% of whatever you give me. It seems to me that both relative and undefined height is an agnostic statement about the window height, and Vaadin should treat the cases equally.

The issue is the combination: ‘whatever you can give’ (100% textfield height) out of ‘I have no idea, I’ll let the child decide’ (undefined window height) is a situation there aren’t good defaults for, so Vaadin can’t really make any guesses to what you want. Instead, it renders the component to zero height so that you notice that something is wrong.

I do agree with you that there could be some default behaviour that takes over here and creates a better initial size (temporary using defaults instead of what the user defined), but I highly doubt that sizing and layout operations will change at this point; we would simply break too many existing apps.