Class WBoxLayout

All Implemented Interfaces:
WLayoutItem
Direct Known Subclasses:
WHBoxLayout, WVBoxLayout

public class WBoxLayout extends WLayout
A layout manager which arranges widgets horizontally or vertically.

This layout manager arranges widgets horizontally or vertically inside the parent container.

The space is divided so that each widget is given its preferred size, and remaining space is divided according to stretch factors among widgets. If not all widgets can be given their preferred size (there is not enough room), then widgets are given a smaller size (down to their minimum size). If necessary, the container (or parent layout) of this layout is resized to meet minimum size requirements.

The preferred width or height of a widget is based on its natural size, where it presents its contents without overflowing. WWidget#resize() or (CSS width, height properties) can be used to adjust the preferred size of a widget.

The minimum width or height of a widget is based on the minimum dimensions of the widget or the nested layout. The default minimum height or width for a widget is 0. It can be specified using WWidget#setMinimumSize() or using CSS min-width or 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 does not have a defined size (by having an explicit size, or by being inside a layout manager), or has has only 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. Note that because of the CSS defaults, a WContainer has by default no height, but inherits the width of its parent widget. The width is thus by default defined.

A layout manager may provide resize handles between items which allow the user to change the automatic layout provided by the layout manager (see setResizable()).

Each item is separated using a constant spacing, which defaults to 6 pixels, and can be changed using setSpacing(). 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(). You can add more space between two widgets using addSpacing().

For each item a stretch factor may be defined, which controls how remaining space is used. Each item is stretched using the stretch factor to fill the remaining space.

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.