Professional Documents
Culture Documents
com
VerticalLayout has 100% default width and undefined height, so it fills the containing layout (or UI) horizontally,
and fits its content vertically. HorizontalLayout has undefined size in both dimensions.
In VerticalLayout, the captions of child components are placed above each component, so the layout would look
as follows:
Declarative Format
Ordered layouts have the following declarative elements:
VerticalLayout v-vertical-layout
HorizontalLayout v-horizontal-layout
FormLayout v-form-layout
https://vaadin.com/docs/-/part/framework/layout/layout-orderedlayout.html 1/7
03/09/2017 VerticalLayout and HorizontalLayout · Vaadin - vaadin.com
spacing spacing[=<boolean>]
margin margin[=<boolean>]
For example:
<vaadin-horizontal-layout width-full>
...
The spacing has a default height or width, which can be customized in CSS. You need to set the height or width for
spacing elements with v-spacingstyle. You also need to specify an enclosing rule element in a CSS selector,
such as v-verticallayout for a VerticalLayout or v-horizontallayout for a HorizontalLayout. You can
also use v-vertical and v-horizontal for all vertically or horizontally ordered layouts, such as FormLayout.
For example, the following sets the amount of spacing for all VerticalLayouts (as well as FormLayouts) in the UI:
https://vaadin.com/docs/-/part/framework/layout/layout-orderedlayout.html 2/7
03/09/2017 VerticalLayout and HorizontalLayout · Vaadin - vaadin.com
Or for HorizontalLayout:
Component widths in HorizontalLayout gives a summary of the sizing options for a HorizontalLayout with
spacing disabled. The figure is broken down in the following subsections.
The both layouts actually have undefined height by default andHorizontalLayout has also undefined width,
while VerticalLayout has 100% relative width.
If such a vertical layout with undefined height continues below the bottom of a window (a Window object), the
window will pop up a vertical scroll bar on the right side of the window area. This way, you get a "web page". The
same applies to Panel.
https://vaadin.com/docs/-/part/framework/layout/layout-orderedlayout.html 3/7
03/09/2017 VerticalLayout and HorizontalLayout · Vaadin - vaadin.com
An exception to the above rule is a case where you have a layout with undefined size that contains a component
with a fixed or undefined size together with one or more components with relative size. In this case, the contained
component with fixed (or undefined) size in a sense defines the size of the containing layout, removing the paradox.
That size is then used for the relatively sized components.
The technique can be used to define the width of a VerticalLayout or the height of a HorizontalLayout.
fixedLayout.setWidth("400px");
Expanding Components
Often, you want to have one component that takes all the available space left over from other components. You
need to set its size as 100% and set it as expanding with setExpandRatio(). The second parameter for the method
is an expansion ratio, which is relevant if there are more than one expanding component, but its value is irrelevant
for a single expanding component.
parentLayout.addComponent(layout);
In the declarative format, you need to specify the :expand attribute in the child components. The attribute defaults
to expand ratio 1.
Notice that you can not call setExpandRatio() before you have added the component to the layout, because it can
not operate on an component that it doesn’t yet have.
Expand Ratios
If you specify an expand ratio for multiple components, they will all try to use the available space according to the
ratio.
https://vaadin.com/docs/-/part/framework/layout/layout-orderedlayout.html 5/7
03/09/2017 VerticalLayout and HorizontalLayout · Vaadin - vaadin.com
As the example used the same ratio for all components, the ones with more content may have the content cut.
Below, we use differing ratios:
If the size of the expanding components is defined as a percentage (typically "100%"), the ratio is calculated from
the overall space available for the relatively sized components. For example, if you have a 100 pixels wide layout
with two cells with 1.0 and 4.0 respective expansion ratios, and both the components in the layout are set
as setWidth("100%"), the cells will have respective widths of 20 and 80 pixels, regardless of the minimum size of
the components.
However, if the size of the contained components is undefined or fixed, the expansion ratio is of
the excess available space. In this case, it is the excess space that expands, not the components.
layout4.addComponent(button);
It is not meaningful to combine expanding components with percentually defined size and components with fixed or
undefined size. Such combination can lead to a very unexpected size for the percentually sized components.
Percentual Sizing
https://vaadin.com/docs/-/part/framework/layout/layout-orderedlayout.html 6/7
03/09/2017 VerticalLayout and HorizontalLayout · Vaadin - vaadin.com
A percentual size of a component defines the size of the component within its cell. Usually, you use "100%", but a
smaller percentage or a fixed size (smaller than the cell size) will leave an empty space in the cell and align the
component within the cell according to its alignment setting, top left by default.
https://vaadin.com/docs/-/part/framework/layout/layout-orderedlayout.html 7/7