Class WGridLayout
- All Implemented Interfaces:
WLayoutItem
This layout manager arranges widgets in a grid.
Each grid cell (row, column) may contain one widget or nested layout. Orientation.Horizontal and vertical space are divided so that each non-stretchable column/row is
given its preferred size (if possible) and the remaining space is divided according to stretch
factors among the columns/rows. If not all columns/rows can be given their preferred size (there
is not enough room), then columns/rows are given a smaller size (down to a minimum size based on
widget minimum sizes). If necessary, the container (or parent layout) of this layout is resized
to meet minimum size requirements.
The preferred width/height of a column/row is based on the natural size of the widgets, where
they present their contents without overflowing. WWidget#resize() or (CSS width, height properties) can be used
to adjust the preferred size of a widget.
The minimum width/height of a column/row is based on the minimum dimensions of contained
widgets or nested layouts. The default minimum height and width for a widget is 0. It can be
specified using WWidget#setMinimumSize() or using CSS min-width and 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 has 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.
A layout manager may provide resize handles between columns or rows which allow the user to
change the automatic layout provided by the layout manager (see setRowResizable() and
setColumnResizable()).
Columns and rows are separated using a constant spacing, which defaults to 6 pixels by
default, and can be changed using setHorizontalSpacing() and setVerticalSpacing(). 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().
For each column or row, a stretch factor may be defined, which controls how remaining horizontal or vertical space is used. Each column and row is stretched using the stretch factor to fill the remaining space. When the stretch factor is 0, the height of the row and its contents is set to the preferred size (if possible). When the stretch factor is 1 or higher, these widgets will be given the remaining size, limited only by their minimum size (their preferred size is ignored).
Usage example:
WContainerWidget w = new WContainerWidget(this);
w.resize(WLength.Auto, new WLength(600));
WGridLayout layout = new WGridLayout();
layout.addWidget(new WText("Item 0 0"), 0, 0);
layout.addWidget(new WText("Item 0 1"), 0, 1);
layout.addWidget(new WText("Item 1 0"), 1, 0);
layout.addWidget(new WText("Item 1 1"), 1, 1);
w.setLayout(layout);
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 voidaddItem(WLayoutItem item, int row, int column) Adds a layout item to the grid.final voidaddItem(WLayoutItem item, int row, int column, int rowSpan) Adds a layout item to the grid.final voidaddItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan) Adds a layout item to the grid.final voidaddItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a layout item to the grid.voidaddItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan, EnumSet<AlignmentFlag> alignment) Adds a layout item to the grid.final voidAdds a nested layout item to the grid.final voidAdds a nested layout item to the grid.final voidaddLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a nested layout item to the grid.voidaddLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan, EnumSet<AlignmentFlag> alignment) Adds a nested layout item to the grid.final voidaddLayout(WLayout layout, int row, int column, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a nested layout item to the grid.voidaddLayout(WLayout layout, int row, int column, EnumSet<AlignmentFlag> alignment) Adds a nested layout item to the grid.final voidAdds a widget to the grid.final voidAdds a widget to the grid.final voidaddWidget(WWidget widget, int row, int column, int rowSpan, int columnSpan, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a widget to the grid.voidaddWidget(WWidget widget, int row, int column, int rowSpan, int columnSpan, EnumSet<AlignmentFlag> alignment) Adds a widget to the grid.final voidaddWidget(WWidget widget, int row, int column, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a widget to the grid.voidaddWidget(WWidget widget, int row, int column, EnumSet<AlignmentFlag> alignment) Adds a widget to the grid.booleancolumnIsResizable(int column) Returns whether the user may drag a particular column border.intReturns the column count.intgetColumnStretch(int column) Returns the column stretch.intgetCount()Returns the number of items in this layout.intReturns the horizontal spacing.getItemAt(int index) Returns the layout item at a specific index.intReturns the row count.intgetRowStretch(int row) Returns the column stretch.intReturns the vertical spacing.voiditerateWidgets(HandleWidgetMethod method) removeItem(WLayoutItem item) Removes a layout item (widget or nested layout).booleanrowIsResizable(int row) Returns whether the user may drag a particular row border.final voidsetColumnResizable(int column) Sets whether the user may drag a particular column border.final voidsetColumnResizable(int column, boolean enabled) Sets whether the user may drag a particular column border.voidsetColumnResizable(int column, boolean enabled, WLength initialSize) Sets whether the user may drag a particular column border.voidsetColumnStretch(int column, int stretch) Sets the column stretch.voidsetHorizontalSpacing(int size) Sets the horizontal spacing.voidsetParentWidget(WWidget parent) Internal method.final voidsetRowResizable(int row) Sets whether the user may drag a particular row border.final voidsetRowResizable(int row, boolean enabled) Sets whether the user may drag a particular row border.voidsetRowResizable(int row, boolean enabled, WLength initialSize) Sets whether the user may drag a particular row border.voidsetRowStretch(int row, int stretch) Sets the row stretch.voidsetVerticalSpacing(int size) Sets the vertical spacing.Methods inherited from class eu.webtoolkit.jwt.WLayout
addWidget, findWidgetItem, getContentsMargin, getImpl, getImplementation, getLayout, getParentLayout, getParentWidget, getPreferredImplementation, getWidget, indexOf, isImplementationIsFlexLayout, itemAdded, itemRemoved, removeWidget, setContentsMargins, setDefaultImplementation, setImpl, setObjectName, setParentLayout, setPreferredImplementation, update, update, updateImplementationMethods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, tr
-
Constructor Details
-
WGridLayout
public WGridLayout()Create a new grid layout.The grid will grow dynamically as items are added.
Use
parent=nullto create a layout manager that can be nested inside other layout managers or if you useWContainerWidget#setLayout()to add specify the container later.
-
-
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(). -
addItem
public void addItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan, EnumSet<AlignmentFlag> alignment) Adds a layout item to the grid.Adds the item at (row,
column). If an item was already added to that location, it is replaced.An item may span several more rows or columns, which is controlled by rowSpan and
columnSpan.The
alignmentspecifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. 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). -
addItem
public final void addItem(WLayoutItem item, int row, int column, int rowSpan, int columnSpan, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a layout item to the grid.Calls
addItem(item, row, column, rowSpan, columnSpan, EnumSet.of(alignmen, alignment)) -
addItem
Adds a layout item to the grid.Calls
addItem(item, row, column, 1, 1, EnumSet.noneOf(AlignmentFlag.class)) -
addItem
Adds a layout item to the grid.Calls
addItem(item, row, column, rowSpan, 1, EnumSet.noneOf(AlignmentFlag.class)) -
addItem
Adds a layout item to the grid.Calls
addItem(item, row, column, rowSpan, columnSpan, EnumSet.noneOf(AlignmentFlag.class)) -
addLayout
Adds a nested layout item to the grid.Adds the layout at (row,
column). If an item was already added to that location, it is replaced (but not deleted).The
alignmentspecifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. 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). -
addLayout
public final void addLayout(WLayout layout, int row, int column, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a nested layout item to the grid.Calls
addLayout(layout, row, column, EnumSet.of(alignmen, alignment)) -
addLayout
Adds a nested layout item to the grid.Calls
addLayout(layout, row, column, EnumSet.noneOf(AlignmentFlag.class)) -
addLayout
public void addLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan, EnumSet<AlignmentFlag> alignment) Adds a nested layout item to the grid.Adds the layout at (row,
column). If an item was already added to that location, it is replaced (but not deleted).An item may span several more rows or columns, which is controlled by rowSpan and
columnSpan.The
alignmentspecifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. 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). -
addLayout
public final void addLayout(WLayout layout, int row, int column, int rowSpan, int columnSpan, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a nested layout item to the grid.Calls
addLayout(layout, row, column, rowSpan, columnSpan, EnumSet.of(alignmen, alignment)) -
addLayout
Adds a nested layout item to the grid.Calls
addLayout(layout, row, column, rowSpan, columnSpan, EnumSet.noneOf(AlignmentFlag.class)) -
addWidget
Adds a widget to the grid.Adds the widget at (row,
column). If an item was already added to that location, it is replaced (but not deleted).The
alignmentspecifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. 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 row, int column, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a widget to the grid.Calls
addWidget(widget, row, column, EnumSet.of(alignmen, alignment)) -
addWidget
Adds a widget to the grid.Calls
addWidget(widget, row, column, EnumSet.noneOf(AlignmentFlag.class)) -
addWidget
public void addWidget(WWidget widget, int row, int column, int rowSpan, int columnSpan, EnumSet<AlignmentFlag> alignment) Adds a widget to the grid.Adds the widget at (row,
column). If an item was already added to that location, it is replaced (but not deleted).The widget may span several more rows or columns, which is controlled by rowSpan and
columnSpan.The
alignmentspecifies the vertical and horizontal alignment of the item. The default value 0 indicates that the item is stretched to fill the entire grid cell. 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 row, int column, int rowSpan, int columnSpan, AlignmentFlag alignmen, AlignmentFlag... alignment) Adds a widget to the grid.Calls
addWidget(widget, row, column, rowSpan, columnSpan, EnumSet.of(alignmen, alignment)) -
addWidget
Adds a widget to the grid.Calls
addWidget(widget, row, column, rowSpan, columnSpan, EnumSet.noneOf(AlignmentFlag.class)) -
setHorizontalSpacing
public void setHorizontalSpacing(int size) Sets the horizontal spacing.The default horizontal spacing is 9 pixels.
- See Also:
-
getHorizontalSpacing
public int getHorizontalSpacing()Returns the horizontal spacing.- See Also:
-
setVerticalSpacing
public void setVerticalSpacing(int size) Sets the vertical spacing.The default vertical spacing is 9 pixels.
- See Also:
-
getVerticalSpacing
public int getVerticalSpacing()Returns the vertical spacing.- See Also:
-
getColumnCount
public int getColumnCount()Returns the column count.The grid dimensions change dynamically when adding contents to the grid.
- See Also:
-
getRowCount
public int getRowCount()Returns the row count.The grid dimensions change dynamically when adding contents to the grid.
- See Also:
-
setColumnStretch
public void setColumnStretch(int column, int stretch) Sets the column stretch.Sets the stretch factor for column
column.- See Also:
-
getColumnStretch
public int getColumnStretch(int column) Returns the column stretch. -
setRowStretch
public void setRowStretch(int row, int stretch) Sets the row stretch.Sets the stretch factor for row
row.- See Also:
-
getRowStretch
public int getRowStretch(int row) Returns the column stretch.- See Also:
-
setColumnResizable
Sets whether the user may drag a particular column border.This method sets whether the border that separates column column from the next column 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 width of the column, overriding the width it would be given by the layout manager. -
setColumnResizable
public final void setColumnResizable(int column) Sets whether the user may drag a particular column border. -
setColumnResizable
public final void setColumnResizable(int column, boolean enabled) Sets whether the user may drag a particular column border. -
columnIsResizable
public boolean columnIsResizable(int column) Returns whether the user may drag a particular column border.This method returns whether the border that separates column column from the next column may be resized by the user.
-
setRowResizable
Sets whether the user may drag a particular row border.This method sets whether the border that separates row row from the next row 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 height of the row, overriding the height it would be given by the layout manager. -
setRowResizable
public final void setRowResizable(int row) Sets whether the user may drag a particular row border. -
setRowResizable
public final void setRowResizable(int row, boolean enabled) Sets whether the user may drag a particular row border. -
rowIsResizable
public boolean rowIsResizable(int row) Returns whether the user may drag a particular row border.This method returns whether the border that separates row row from the next row may be resized by the user.
-
iterateWidgets
-
setParentWidget
Description copied from interface:WLayoutItemInternal method.- Specified by:
setParentWidgetin interfaceWLayoutItem- Overrides:
setParentWidgetin classWLayout
-