Class WBoxLayout
- All Implemented Interfaces:
WLayoutItem
- Direct Known Subclasses:
WHBoxLayout,WVBoxLayout
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddItem(WLayoutItem item) Adds a layout item.final voidAdds a nested layout to the layout.final voidAdds a nested layout to the layout.final voidaddLayout(WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a nested layout to the layout.voidaddLayout(WLayout layout, int stretch, EnumSet<AlignmentFlag> alignment) Adds a nested layout to the layout.voidaddSpacing(WLength size) Adds extra spacing.final voidAdds a stretch element.voidaddStretch(int stretch) Adds a stretch element.final voidAdds a widget to the layout.final voidAdds a widget to the layout.final voidaddWidget(WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a widget to the layout.voidaddWidget(WWidget widget, int stretch, EnumSet<AlignmentFlag> alignment) Adds a widget to the layout.intgetCount()Returns the number of items in this layout.Returns the layout direction.getItemAt(int index) Returns the layout item at a specific index.intReturns the spacing between each item.protected final voidinsertItem(int index, WLayoutItem item, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) protected voidinsertItem(int index, WLayoutItem item, int stretch, EnumSet<AlignmentFlag> alignment) final voidinsertLayout(int index, WLayout layout) Inserts a nested layout in the layout.final voidinsertLayout(int index, WLayout layout, int stretch) Inserts a nested layout in the layout.final voidinsertLayout(int index, WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Inserts a nested layout in the layout.voidinsertLayout(int index, WLayout layout, int stretch, EnumSet<AlignmentFlag> alignment) Inserts a nested layout in the layout.voidinsertSpacing(int index, WLength size) Inserts extra spacing in the layout.final voidinsertStretch(int index) Inserts a stretch element in the layout.voidinsertStretch(int index, int stretch) Inserts a stretch element in the layout.final voidinsertWidget(int index, WWidget widget) Inserts a widget in the layout.final voidinsertWidget(int index, WWidget widget, int stretch) Inserts a widget in the layout.final voidinsertWidget(int index, WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Inserts a widget in the layout.voidinsertWidget(int index, WWidget widget, int stretch, EnumSet<AlignmentFlag> alignment) Inserts a widget in the layout.booleanbooleanisResizable(int index) Returns whether the user may drag a particular border.voiditerateWidgets(HandleWidgetMethod method) removeItem(WLayoutItem item) Removes a layout item (widget or nested layout).voidsetDirection(LayoutDirection direction) Sets the layout direction.voidsetParentWidget(WWidget parent) Internal method.final voidsetResizable(int index) Sets whether the use may drag a particular border.final voidsetResizable(int index, boolean enabled) Sets whether the use may drag a particular border.voidsetResizable(int index, boolean enabled, WLength initialSize) Sets whether the use may drag a particular border.voidsetSpacing(int size) Sets spacing between each item.booleansetStretchFactor(WLayout layout, int stretch) Sets the stretch factor for a nested layout.booleansetStretchFactor(WWidget widget, int stretch) Sets the stretch factor for a widget.protected voidMethods inherited from class eu.webtoolkit.jwt.WLayout
findWidgetItem, getContentsMargin, getImpl, getImplementation, getLayout, getParentLayout, getParentWidget, getPreferredImplementation, getWidget, indexOf, itemAdded, itemRemoved, removeWidget, setContentsMargins, setDefaultImplementation, setImpl, setObjectName, setParentLayout, setPreferredImplementation, update, updateMethods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, tr
-
Constructor Details
-
WBoxLayout
Creates a new box layout.This constructor is rarely used. Instead, use the convenient constructors of the specialized
WHBoxLayoutorWVBoxLayoutclasses.Use
parent=nullto created a layout manager that can be nested inside other layout managers.
-
-
Method Details
-
addItem
Description copied from class:WLayoutAdds a layout item.The item may be a widget or nested layout.
How the item is layed out with respect to siblings is implementation specific to the layout manager. In some cases, a layout manager will overload this method with extra arguments that specify layout options.
-
removeItem
Description copied from class:WLayoutRemoves a layout item (widget or nested layout).- Specified by:
removeItemin classWLayout- See Also:
-
getItemAt
Description copied from class:WLayoutReturns the layout item at a specific index.If there is no item at the
index,nullis returned. -
getCount
public int getCount()Description copied from class:WLayoutReturns the number of items in this layout.This may be a theoretical number, which is greater than the actual number of items. It can be used to iterate over the items in the layout, in conjunction with
getItemAt(). -
setDirection
Sets the layout direction.Note: Changing the layout direction after something (a widget or nested layout) has been added is not supported.
- See Also:
-
getDirection
Returns the layout direction.- See Also:
-
setSpacing
public void setSpacing(int size) Sets spacing between each item.The default spacing is 6 pixels.
-
getSpacing
public int getSpacing()Returns the spacing between each item.- See Also:
-
addWidget
Adds a widget to the layout.Adds a widget to the layout, with given
stretchfactor. When the stretch factor is 0, the widget will not be resized by the layout manager (stretched to take excess space).The
alignmentparameter is a combination of a horizontal and/or a vertical AlignmentFlag OR'ed together.The
alignmentspecifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire column or row. The alignment can be specified as a logical combination of a horizontal alignment (AlignmentFlag.Left,AlignmentFlag.Center, orAlignmentFlag.Right) and a vertical alignment (AlignmentFlag.Top,AlignmentFlag.Middle, orAlignmentFlag.Bottom). -
addWidget
public final void addWidget(WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a widget to the layout.Calls
addWidget(widget, stretch, EnumSet.of(alignmen, alignment)) -
addWidget
Adds a widget to the layout.Calls
addWidget(widget, 0, EnumSet.noneOf(AlignmentFlag.class)) -
addWidget
Adds a widget to the layout.Calls
addWidget(widget, stretch, EnumSet.noneOf(AlignmentFlag.class)) -
addLayout
Adds a nested layout to the layout.Adds a nested layout, with given
stretchfactor. -
addLayout
public final void addLayout(WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a nested layout to the layout.Calls
addLayout(layout, stretch, EnumSet.of(alignmen, alignment)) -
addLayout
Adds a nested layout to the layout.Calls
addLayout(layout, 0, EnumSet.noneOf(AlignmentFlag.class)) -
addLayout
Adds a nested layout to the layout.Calls
addLayout(layout, stretch, EnumSet.noneOf(AlignmentFlag.class)) -
addSpacing
Adds extra spacing.Adds extra spacing to the layout.
-
addStretch
public void addStretch(int stretch) Adds a stretch element.Adds a stretch element to the layout. This adds an empty space that stretches as needed.
-
addStretch
public final void addStretch()Adds a stretch element.Calls
addStretch(0) -
insertWidget
Inserts a widget in the layout.Inserts a widget in the layout at position
index, with givenstretchfactor. When the stretch factor is 0, the widget will not be resized by the layout manager (stretched to take excess space).The
alignmentspecifies the vertical and horizontal alignment of the item. The default value None indicates that the item is stretched to fill the entire column or row. The alignment can be specified as a logical combination of a horizontal alignment (AlignmentFlag.Left,AlignmentFlag.Center, orAlignmentFlag.Right) and a vertical alignment (AlignmentFlag.Top,AlignmentFlag.Middle, or Wt::AlignmentFlag::AlignBottom). -
insertWidget
public final void insertWidget(int index, WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Inserts a widget in the layout.Calls
insertWidget(index, widget, stretch, EnumSet.of(alignmen, alignment)) -
insertWidget
Inserts a widget in the layout.Calls
insertWidget(index, widget, 0, EnumSet.noneOf(AlignmentFlag.class)) -
insertWidget
Inserts a widget in the layout.Calls
insertWidget(index, widget, stretch, EnumSet.noneOf(AlignmentFlag.class)) -
insertLayout
Inserts a nested layout in the layout.Inserts a nested layout in the layout at position
index, with givenstretchfactor. -
insertLayout
public final void insertLayout(int index, WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) Inserts a nested layout in the layout.Calls
insertLayout(index, layout, stretch, EnumSet.of(alignmen, alignment)) -
insertLayout
Inserts a nested layout in the layout.Calls
insertLayout(index, layout, 0, EnumSet.noneOf(AlignmentFlag.class)) -
insertLayout
Inserts a nested layout in the layout.Calls
insertLayout(index, layout, stretch, EnumSet.noneOf(AlignmentFlag.class)) -
insertSpacing
Inserts extra spacing in the layout.Inserts extra spacing in the layout at position
index. -
insertStretch
public void insertStretch(int index, int stretch) Inserts a stretch element in the layout.Inserts a stretch element in the layout at position
index. This adds an empty space that stretches as needed. -
insertStretch
public final void insertStretch(int index) Inserts a stretch element in the layout.Calls
insertStretch(index, 0) -
setStretchFactor
Sets the stretch factor for a nested layout.The
layoutmust have previously been added to this layout usinginsertLayout()oraddLayout().Returns whether the
stretchcould be set. -
setStretchFactor
Sets the stretch factor for a widget.The
widgetmust have previously been added to this layout usinginsertWidget()oraddWidget().Returns whether the
stretchcould be set. -
setResizable
Sets whether the use may drag a particular border.This method sets whether the border that separates item index from the next item may be resized by the user, depending on the value of enabled.
The default value is false.
If an
initialSizeis given (that is notWLength.Auto), then this size is used for the size of the item, overriding the size it would be given by the layout manager. -
setResizable
public final void setResizable(int index) Sets whether the use may drag a particular border. -
setResizable
public final void setResizable(int index, boolean enabled) Sets whether the use may drag a particular border. -
isResizable
public boolean isResizable(int index) Returns whether the user may drag a particular border.This method returns whether the border that separates item index from the next item may be resized by the user.
-
iterateWidgets
-
isImplementationIsFlexLayout
public boolean isImplementationIsFlexLayout()- Overrides:
isImplementationIsFlexLayoutin classWLayout
-
insertItem
protected void insertItem(int index, WLayoutItem item, int stretch, EnumSet<AlignmentFlag> alignment) -
insertItem
protected final void insertItem(int index, WLayoutItem item, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment) -
updateImplementation
protected void updateImplementation()- Overrides:
updateImplementationin classWLayout
-
setParentWidget
Description copied from interface:WLayoutItemInternal method.- Specified by:
setParentWidgetin interfaceWLayoutItem- Overrides:
setParentWidgetin classWLayout
-