Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Hide row in GridLayout problem
I have a component that extends GridLayout and it shows several Labels, PopupDateFields and NativeSelects in about 10 rows and 4 columns. Depending on a state variable I need to hide the components of special rows. I'm doing this by hiding all components of a row.
This works so far, but the hidden rows leave some empty space between the displayed rows and that doesn't look very nice. I did already tried the setRowExpandRatio() method with a ratio value of 0 for the hidden rows, but that didn't help either.
Is there a possibility to remove this empty space or do I have to fill the GridLayout with only the visible components?
Thanks in advance
I haven't tried myself but did you check that the grid layout or any layout inside each cell does not have margins (setMargins(false))
This may cause Vaadin to render them as blank space.
setting GridLayout.setMargin(false) doesn't change a bit. When I set GridLayout.setSpacing(false), the empty space between the cells is reduced but the Layout doesn't look nice anymore. Inside each cell is no other layout container, just pure components (Label, TextField, NativeSelect).
I did look at the generated html code via Firebug and there I could see that all the positioning inside GridLayout is done with absolute positions. I think this is not a margin or padding problem.
Maybe we should have something like a hideRow(int row) method for GridLayout in order to get the desired behaviour.
have you found a solution for this problem?
I have encountered this issue several times and my solution is to remove all components from the layout when the state changes (i.e. when you select a value in a combo-box) and then add the components again; but this time only those which should be visible. All you need to do is to remember the components you added to the layout. It's not a perfect solution but it works!
I have the same issue. Seems ticket https://dev.vaadin.com/ticket/8855 is not fixed yet. Or is for this a "special method" such as hideRow(x)?
There is a method setHideEmptyRowsAndColumns in GridLayout.
It clean extra space away if row or col is not visible