Class WGridLayout

All Implemented Interfaces:

public class WGridLayout extends WLayout
A layout manager which arranges widgets in a grid.

This layout manager arranges widgets in a grid.

Each grid cell (row, column) may contain one widget or nested layout. Orientation.Horizontal and vertical space are divided so that each non-stretchable column/row is given its preferred size (if possible) and the remaining space is divided according to stretch factors among the columns/rows. If not all columns/rows can be given their preferred size (there is not enough room), then columns/rows are given a smaller size (down to a minimum size based on widget minimum sizes). If necessary, the container (or parent layout) of this layout is resized to meet minimum size requirements.

The preferred width/height of a column/row is based on the natural size of the widgets, where they present their contents without overflowing. WWidget#resize() or (CSS width, height properties) can be used to adjust the preferred size of a widget.

The minimum width/height of a column/row is based on the minimum dimensions of contained widgets or nested layouts. The default minimum height and width for a widget is 0. It can be specified using WWidget#setMinimumSize() or using CSS min-width and min-height properties.

You should use WContainerWidget#setOverflow() to automatically show scrollbars for widgets inserted in the layout to cope with a size set by the layout manager that is smaller than the preferred size.

When the container of a layout manager has a maximum size set using WWidget#setMaximumSize(), then the size of the container will be based on the preferred size of the contents, up to this maximum size, instead of the default behaviour of constraining the size of the children based on the size of the container.

A layout manager may provide resize handles between columns or rows which allow the user to change the automatic layout provided by the layout manager (see setRowResizable() and setColumnResizable()).

Columns and rows are separated using a constant spacing, which defaults to 6 pixels by default, and can be changed using setHorizontalSpacing() and setVerticalSpacing(). In addition, when this layout is a top-level layout (i.e. is not nested inside another layout), a margin is set around the contents. This margin defaults to 9 pixels, and can be changed using WLayout#setContentsMargins().

For each column or row, a stretch factor may be defined, which controls how remaining horizontal or vertical space is used. Each column and row is stretched using the stretch factor to fill the remaining space. When the stretch factor is 0, the height of the row and its contents is set to the preferred size (if possible). When the stretch factor is 1 or higher, these widgets will be given the remaining size, limited only by their minimum size (their preferred size is ignored).

Usage example:

 WContainerWidget w = new WContainerWidget(this);
 w.resize(WLength.Auto, new WLength(600));

 WGridLayout layout = new WGridLayout();
 layout.addWidget(new WText("Item 0 0"), 0, 0);
 layout.addWidget(new WText("Item 0 1"), 0, 1);
 layout.addWidget(new WText("Item 1 0"), 1, 0);
 layout.addWidget(new WText("Item 1 1"), 1, 1);



Note: When JavaScript support is not available, not all functionality of the layout is available. In particular, vertical size management is not available.

Note: When a layout is used on a first page with progressive bootstrap, then the layout will progress only in a limited way to a full JavaScript-based layout. You can thus not rely on it to behave properly for example when dynamically adding or removing widgets.