Ideas for GridLayout

A few comments about GridLayout, ideas to consider when making changes in Vaadin 7.


GridLayout with undefined size should automatically expand its width when adding components. Currently if you add a series of widgets, they end up arranged in a stack as with a VerticalLayout. This contradicts the definition of GridLayout which is a series of cells laid out as we read, left to right, top to bottom. Given that GridLayout already has the verbs newline() and space(), GridLayout should behave like a typewriter. On a typewriter, each letter you type is added to the current line. Then you hit Carriage Return to move to the next line. So each call to addComponent should move the cursor in GridLayout to the right, on the same line, expanding the column count as needed. When the programmer wants a new row, she calls newline().


Almost always, Labels should butt up against the field they describe. Yet in GroupLayout I must repeatedly call:
layout.setComponentAlignment( label, Alignment.MIDDLE_RIGHT );
There must be some easier way. I don’t know the answer given your current architecture, but there must be a better way.

Perhaps redefine GridLayout’s behavior so that if the component being passed is a Label, then change the alignment to middle right. Perhaps for backward compatibility, have a setter to revert to old behavior.


Similar to item above, in a GridLayout, TextFields should default to width is 100%. The main reason a programmer would be using GridLayout is to get “boxy” arrangement of groups of fields (rather than arbitrary field lengths that give a jagged “noisy” appearance), in the style of NeXTSTEP and Mac OS X. So TextFields should fill their cell to line up with their siblings.

Again I don’t know the best answer. I just know the problem.

–Basil Bourque

A few of my personal opinions:

A gridlayout doesn’t stack up vertically if you just add components to it. It stacks up as a grid. it goes from left to right, top to down. Only reason why it would stack up as a grid is that you have a column wide grid (which I guess is the default if you just create it with new GridLyout()).

Personally, I don’t fancy the thing that the column amount would grow. I like to just do addComponent(label1); addComponent(field2); addComponent(label2); addComponent(field2); and they stack up nicely on a two column gridlayout.

This is a quite dangerous assumption to do. The thing that everything you do behaves in one way (in this case TOP_LEFT) and then one specific case behaves in a different matter (here MIDDLE_RIGHT). Another thing you would have to do is set label.setWIdth(null); automatically when a label is set to the gridlayout, as labels have a 100% default width and setting alignment doesn’t affect anything when it tries to take too much space.

Having the label right aligned might make the layout look a little bit cleaner in some cases, but I find that having them left aligned is more readable. Also there a bunch of cases where you have labels in a gridlayout that doesn’t have anything to do with fields, where it wouldn’t make sense to right align it.

Same argument here, having some special rules depending on where you put it makes it unpredictable and might frustrate the developers. Also, having the fields as 100% width and the gridlayout as size undefined, as you mentioned in the start of your post, would make the fields dissapear. Undefined gridlayout would give the fields exactly that much space as the components ask for, and when the components ask for 100% of undefined, they end up with 0 pixels of width.

I think one of the stronger sides of Vaadin is that it is fairly simple to understand, and adding these kinds of special rules brings in complexity, and a set of defaults that might not be at all more appropriate the the next developer, even if it would be that for me or you.