Containers

The primary method for combining a number of widgets in a composite widget is a WContainerWidget. This widget corresponds to an HTML <span> or <div> element (depending on whether it is inline or not). It can contain any number of children, and these children may be added or removed dynamically.

Example
A first widget

Text 0

Text 1

Text 2

source
  void Container() {
    WContainerWidget container = new WContainerWidget();
    new WText("A first widget", (WContainerWidget) container);
    for (int i = 0; i < 3; ++i) {
      new WText(new WString("<p>Text {1}</p>").arg(i), (WContainerWidget) container);
    }
  }

Alternatives to consider are a WTemplate, which puts widgets inside an HTML fragment using placeholder substitution, or a WTable for organizing children in a table (without using a layout manager).

As a fundamental building block of JWt, a container widget itself usually does not have any visual aspect (although it can very well be styled to give it for example margin and borders). The widgets that are contained can be positioned using Cascading StyleSheets (CSS) or a Layout Manager. CSS, which to most Java developers will be a new technology, is worthwhile learning as it will allow you to push many layout and style aspects of your application into a declarative text file. It also works irrespective of JavaScript, which is a clear benefit over layout managers. The latter are however the superior (and only) choice in case vertical fitting or stretching of children to the height of the container is needed.

There are several specialized container classes that have additional markup or behaviour: