Class WBoxLayout
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WLayout
-
- eu.webtoolkit.jwt.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 (CSSwidth,heightproperties) 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 CSSmin-widthormin-heightproperties.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 usingWLayout#setContentsMargins(). You can add more space between two widgets usingaddSpacing().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 Constructor Description WBoxLayout(LayoutDirection dir)Creates a new box layout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddItem(WLayoutItem item)Adds a layout item.voidaddLayout(WLayout layout)Adds a nested layout to the layout.voidaddLayout(WLayout layout, int stretch)Adds a nested layout to the layout.voidaddLayout(WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)Adds a nested layout to the layout.voidaddLayout(WLayout layout, int stretch, java.util.EnumSet<AlignmentFlag> alignment)Adds a nested layout to the layout.voidaddSpacing(WLength size)Adds extra spacing.voidaddStretch()Adds a stretch element.voidaddStretch(int stretch)Adds a stretch element.voidaddWidget(WWidget widget)Adds a widget to the layout.voidaddWidget(WWidget widget, int stretch)Adds a widget to the layout.voidaddWidget(WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)Adds a widget to the layout.voidaddWidget(WWidget widget, int stretch, java.util.EnumSet<AlignmentFlag> alignment)Adds a widget to the layout.intgetCount()Returns the number of items in this layout.LayoutDirectiongetDirection()Returns the layout direction.WLayoutItemgetItemAt(int index)Returns the layout item at a specific index.intgetSpacing()Returns the spacing between each item.protected voidinsertItem(int index, WLayoutItem item, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)protected voidinsertItem(int index, WLayoutItem item, int stretch, java.util.EnumSet<AlignmentFlag> alignment)voidinsertLayout(int index, WLayout layout)Inserts a nested layout in the layout.voidinsertLayout(int index, WLayout layout, int stretch)Inserts a nested layout in the layout.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, java.util.EnumSet<AlignmentFlag> alignment)Inserts a nested layout in the layout.voidinsertSpacing(int index, WLength size)Inserts extra spacing in the layout.voidinsertStretch(int index)Inserts a stretch element in the layout.voidinsertStretch(int index, int stretch)Inserts a stretch element in the layout.voidinsertWidget(int index, WWidget widget)Inserts a widget in the layout.voidinsertWidget(int index, WWidget widget, int stretch)Inserts a widget in the layout.voidinsertWidget(int index, WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)Inserts a widget in the layout.voidinsertWidget(int index, WWidget widget, int stretch, java.util.EnumSet<AlignmentFlag> alignment)Inserts a widget in the layout.booleanisImplementationIsFlexLayout()booleanisResizable(int index)Returns whether the user may drag a particular border.voiditerateWidgets(HandleWidgetMethod method)WLayoutItemremoveItem(WLayoutItem item)Removes a layout item (widget or nested layout).voidsetDirection(LayoutDirection direction)Sets the layout direction.voidsetParentWidget(WWidget parent)Internal method.voidsetResizable(int index)Sets whether the use may drag a particular border.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 voidupdateImplementation()-
Methods 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, update
-
Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, tr
-
-
-
-
Constructor Detail
-
WBoxLayout
public WBoxLayout(LayoutDirection dir)
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 Detail
-
addItem
public void addItem(WLayoutItem item)
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.
- Specified by:
addItemin classWLayout- See Also:
WLayout.removeItem(WLayoutItem item)
-
removeItem
public WLayoutItem removeItem(WLayoutItem item)
Description copied from class:WLayoutRemoves a layout item (widget or nested layout).- Specified by:
removeItemin classWLayout- See Also:
WLayout.removeWidget(WWidget w)
-
getItemAt
public WLayoutItem getItemAt(int index)
Description copied from class:WLayoutReturns the layout item at a specific index.If there is no item at the
index,nullis returned.- Specified by:
getItemAtin classWLayout- See Also:
WLayout.indexOf(WLayoutItem item),WLayout.getCount()
-
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
public void setDirection(LayoutDirection direction)
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()
-
getDirection
public LayoutDirection getDirection()
Returns the layout direction.- See Also:
setDirection(LayoutDirection direction)
-
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:
setSpacing(int size)
-
addWidget
public void addWidget(WWidget widget, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
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
public final void addWidget(WWidget widget)
Adds a widget to the layout.Calls
addWidget(widget, 0, EnumSet.noneOf(AlignmentFlag.class))- Overrides:
addWidgetin classWLayout- See Also:
WLayout.removeWidget(WWidget w)
-
addWidget
public final void addWidget(WWidget widget, int stretch)
Adds a widget to the layout.Calls
addWidget(widget, stretch, EnumSet.noneOf(AlignmentFlag.class))
-
addLayout
public void addLayout(WLayout layout, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
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
public final void addLayout(WLayout layout)
Adds a nested layout to the layout.Calls
addLayout(layout, 0, EnumSet.noneOf(AlignmentFlag.class))
-
addLayout
public final void addLayout(WLayout layout, int stretch)
Adds a nested layout to the layout.Calls
addLayout(layout, stretch, EnumSet.noneOf(AlignmentFlag.class))
-
addSpacing
public void addSpacing(WLength size)
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
public void insertWidget(int index, WWidget widget, int stretch, java.util.EnumSet<AlignmentFlag> alignment)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
public final void insertWidget(int index, WWidget widget)Inserts a widget in the layout.Calls
insertWidget(index, widget, 0, EnumSet.noneOf(AlignmentFlag.class))
-
insertWidget
public final void insertWidget(int index, WWidget widget, int stretch)Inserts a widget in the layout.Calls
insertWidget(index, widget, stretch, EnumSet.noneOf(AlignmentFlag.class))
-
insertLayout
public void insertLayout(int index, WLayout layout, int stretch, java.util.EnumSet<AlignmentFlag> alignment)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
public final void insertLayout(int index, WLayout layout)Inserts a nested layout in the layout.Calls
insertLayout(index, layout, 0, EnumSet.noneOf(AlignmentFlag.class))
-
insertLayout
public final void insertLayout(int index, WLayout layout, int stretch)Inserts a nested layout in the layout.Calls
insertLayout(index, layout, stretch, EnumSet.noneOf(AlignmentFlag.class))
-
insertSpacing
public void insertSpacing(int index, WLength size)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
public boolean setStretchFactor(WLayout layout, int stretch)
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
public boolean setStretchFactor(WWidget widget, int stretch)
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
public void setResizable(int index, boolean enabled, WLength initialSize)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
public void iterateWidgets(HandleWidgetMethod method)
-
isImplementationIsFlexLayout
public boolean isImplementationIsFlexLayout()
- Overrides:
isImplementationIsFlexLayoutin classWLayout
-
insertItem
protected void insertItem(int index, WLayoutItem item, int stretch, java.util.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
public void setParentWidget(WWidget parent)
Description copied from interface:WLayoutItemInternal method.- Specified by:
setParentWidgetin interfaceWLayoutItem- Overrides:
setParentWidgetin classWLayout
-
-