Layout behavior of FormLayout changes when we toggle visibility of components under it.
An example code is given below. The “Test” button can be clicked to toggle the visibility of the first TextField.
When the text field is made hidden, gaps between rest of the text fields disappear! Screen-shots are attached.
public class TestFormLayout extends FormLayout {
public TestFormLayout() {
TextField tf = new TextField("One");
add(new Button("Test", e -> tf.setVisible(!tf.isVisible())));
add(tf);
add(new TextField("Two"));
add(new TextField("Three"));
add(new TextField("Four"));
add(new TextField("Five"));
add(new TextField("Six"));
}
}