Class WBoxLayout
- All Implemented Interfaces:
WLayoutItem
- Direct Known Subclasses:
WHBoxLayout
,WVBoxLayout
public class WBoxLayout extends WLayout
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()
or use a WScrollArea
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 Modifier and Type Class Description static class
WBoxLayout.Direction
Enumeration of the direction in which widgets are layed out.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WBoxLayout(WBoxLayout.Direction dir)
Creates a new box layout.WBoxLayout(WBoxLayout.Direction dir, WWidget parent)
Creates a new box layout. -
Method Summary
Modifier and Type Method Description void
addItem(WLayoutItem item)
Adds a layout item.void
addLayout(WLayout layout)
Adds a nested layout to the layout.void
addLayout(WLayout layout, int stretch)
Adds a nested layout to the layout.void
addLayout(WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)
Adds a nested layout to the layout.void
addLayout(WLayout layout, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
Adds a nested layout to the layout.void
addSpacing(WLength size)
Adds extra spacing.void
addStretch()
Adds a stretch element.void
addStretch(int stretch)
Adds a stretch element.void
addWidget(WWidget widget)
Adds a widget to the layout.void
addWidget(WWidget widget, int stretch)
Adds a widget to the layout.void
addWidget(WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)
Adds a widget to the layout.void
addWidget(WWidget widget, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
Adds a widget to the layout.void
clear()
Removes and deletes all child widgets and nested layouts.int
getCount()
Returns the number of items in this layout.WBoxLayout.Direction
getDirection()
Returns the layout direction.WLayoutItem
getItemAt(int index)
Returns the layout item at a specific index.int
getSpacing()
Returns the spacing between each item.protected void
insertItem(int index, WLayoutItem item, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)
protected void
insertItem(int index, WLayoutItem item, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
void
insertLayout(int index, WLayout layout)
Inserts a nested layout in the layout.void
insertLayout(int index, WLayout layout, int stretch)
Inserts a nested layout in the layout.void
insertLayout(int index, WLayout layout, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)
Inserts a nested layout in the layout.void
insertLayout(int index, WLayout layout, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
Inserts a nested layout in the layout.void
insertSpacing(int index, WLength size)
Inserts extra spacing in the layout.void
insertStretch(int index)
Inserts a stretch element in the layout.void
insertStretch(int index, int stretch)
Inserts a stretch element in the layout.void
insertWidget(int index, WWidget widget)
Inserts a widget in the layout.void
insertWidget(int index, WWidget widget, int stretch)
Inserts a widget in the layout.void
insertWidget(int index, WWidget widget, int stretch, AlignmentFlag alignmen, AlignmentFlag... alignment)
Inserts a widget in the layout.void
insertWidget(int index, WWidget widget, int stretch, java.util.EnumSet<AlignmentFlag> alignment)
Inserts a widget in the layout.boolean
isResizable(int index)
Returns whether the user may drag a particular border.void
removeItem(WLayoutItem item)
Removes a layout item (widget or nested layout).void
setDirection(WBoxLayout.Direction direction)
Sets the layout direction.void
setResizable(int index)
Sets whether the use may drag a particular border.void
setResizable(int index, boolean enabled)
Sets whether the use may drag a particular border.void
setResizable(int index, boolean enabled, WLength initialSize)
Sets whether the use may drag a particular border.void
setSpacing(int size)
Sets spacing between each item.boolean
setStretchFactor(WLayout layout, int stretch)
Sets the stretch factor for a nested layout.boolean
setStretchFactor(WWidget widget, int stretch)
Sets the stretch factor for a widget.Methods inherited from class eu.webtoolkit.jwt.WLayout
clearLayoutItem, findWidgetItem, getContentsMargin, getImpl, getLayout, getParentLayout, getWidget, indexOf, removeWidget, setContentsMargins, setLayoutHint, setLayoutInParent, setParentLayout, setParentWidget, update, update, updateAddItem, updateRemoveItem
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WBoxLayout
Creates a new box layout.This constructor is rarely used. Instead, use the convenient constructors of the specialized
WHBoxLayout
orWVBoxLayout
classes.Use
parent
=null
to created a layout manager that can be nested inside other layout managers. -
WBoxLayout
Creates a new box layout.Calls
this(dir, (WWidget)null)
-
-
Method Details
-
addItem
Description copied from class:WLayout
Adds 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:
addItem
in classWLayout
- See Also:
WLayout.removeItem(WLayoutItem item)
,WLayout.addWidget(WWidget w)
-
removeItem
Description copied from class:WLayout
Removes a layout item (widget or nested layout).- Specified by:
removeItem
in classWLayout
- See Also:
WLayout.addItem(WLayoutItem item)
,WLayout.removeWidget(WWidget w)
-
getItemAt
Description copied from class:WLayout
Returns the layout item at a specific index.If there is no item at the
index
,null
is returned.- Specified by:
getItemAt
in classWLayout
- See Also:
WLayout.indexOf(WLayoutItem item)
,WLayout.getCount()
-
getCount
public int getCount()Description copied from class:WLayout
Returns 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()
. -
clear
public void clear()Description copied from class:WLayout
Removes and deletes all child widgets and nested layouts.This is similar to
WContainerWidget.clear()
, with the exception that the layout itself is not deleted. -
setDirection
Sets the layout direction.- See Also:
getDirection()
-
getDirection
Returns the layout 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
Adds a widget to the layout.Adds a widget to the layout, with given
stretch
factor. When the stretch factor is 0, the widget will not be resized by the layout manager (stretched to take excess space).The
alignment
parameter is a combination of a horizontal and/or a vertical AlignmentFlag OR'ed together.The
alignment
specifies 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.AlignLeft
,AlignmentFlag.AlignCenter
, orAlignmentFlag.AlignRight
) and a vertical alignment (AlignmentFlag.AlignTop
,AlignmentFlag.AlignMiddle
, orAlignmentFlag.AlignBottom
). -
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))
- Overrides:
addWidget
in classWLayout
- See Also:
WLayout.removeWidget(WWidget w)
,WLayout.addItem(WLayoutItem item)
-
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
stretch
factor. -
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
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 givenstretch
factor. When the stretch factor is 0, the widget will not be resized by the layout manager (stretched to take excess space).The
alignment
specifies 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.AlignLeft
,AlignmentFlag.AlignCenter
, orAlignmentFlag.AlignRight
) and a vertical alignment (AlignmentFlag.AlignTop
,AlignmentFlag.AlignMiddle
, orAlignmentFlag.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
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 givenstretch
factor. -
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
layout
must have previously been added to this layout usinginsertLayout()
oraddLayout()
.Returns whether the
stretch
could be set. -
setStretchFactor
Sets the stretch factor for a widget.The
widget
must have previously been added to this layout usinginsertWidget()
oraddWidget()
.Returns whether the
stretch
could 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
initialSize
is 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.
-
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)
-