Class WContainerWidget

Direct Known Subclasses:
IndexContainerWidget, WAnchor, WDeferred, WFileDropWidget, WGroupBox, WMenuItem, WOverlayLoadingIndicator, WStackedWidget, WTableCell

public class WContainerWidget
extends WInteractWidget
A widget that holds and manages child widgets.

A WContainerWidget acts as a container for child widgets. Child widgets may be added directly to the container or using a layout manager.

Use addWidget() or pass the container as constructor argument to a widget to directly add children to the container, without using a layout manager. In that case, CSS-based layout is used, and the resulting display is determined by properties of the children and the container. By default, a WContainerWidget is displayed as a block and manages its children within a rectangle. Inline child widgets are layed out in lines, wrapping around as needed, while block child widgets are stacked vertically. The container may add padding at the container edges using setPadding(), and provide alignment of contents using setContentAlignment(). A container is rendered by default using a HTML div tag, but this may be changed to an HTML ul or ol tag to make use of other CSS layout techniques, using setList(). In addition, specializations of this class as implemented by WAnchor, WGroupBox, WStackedWidget and WTableCell provide other alternative rendering of the container.

When setting the WContainerWidget inline the container only acts as a conceptual container, offering a common style to its children. Inline children are still layed out inline within the flow of the parent container of this container, as if they were inserted directly into that parent container. Block children are then not allowed (according to the HTML specification).

To use a layout manager instead of CSS-based layout, use setLayout() or pass the container as constructor argument to a layout manager. In that case you should not define any padding for the container, and widgets and nested layout managers must be added to the layout manager, instead of to the container directly.

Usage example:

 // Example 1:
 // Instantiate a container widget and add some children whose layout
 // is governed based on HTML/CSS rules.
 WContainerWidget container1 = new WContainerWidget();
 container1.addWidget(new WText("Some text"));
 container1.addWidget(new WImage("images/img.png"));
 WContainerWidget child3 = new WContainerWidget(container1);

 // Example 2:
 // Instantiate a container widget which uses a layout manager
 WContainerWidget container2 = new WContainerWidget();
 // give the container a fixed height
 container2.resize(WLength.Auto, new WLength(600));

 WVBoxLayout layout = new WVBoxLayout();
 layout.addWidget(new WText("Some text"));
 layout.addWidget(new WImage("images/img.png"));

 container2.setLayout(layout);      // set the layout to the container.


When using a layout manager, you need to carefully consider the alignment of the layout manager with respect to the container: when the container's height is unconstrained (not specified explicitly using WWebWidget#resize() or a style class, and the container is not included in a layout manager), you should pass AlignTop to setLayout().


Depending on its configuration and usage, the widget corresponds to the following HTML tags:

  • By default, the widget corresponds to a <div> tag.
  • When configured with setInline(true), the widget corresponds to a <span> .
  • When configured with setList(true), the widget corresponds to a <ul>.
  • When configured with setList(true, true), the widget corresponds to a <ol> .
  • When inserted into a container widget that isList(), the widget corresponds to a <li>.

This widget does not provide styling, and can be styled using inline or external CSS as appropriate.