public class Grid extends Container
All the children are laid out in a grid, which has a fixed number of columns if the grid is horizontal, or a fixed number of rows if the grid is vertical.
In a grid, all children have the same width and the same height, regardless of their optimal size.
Horizontal:
Vertical:
NO_CONSTRAINT
Constructor and Description |
---|
Grid(boolean orientation,
int count)
Creates a grid specifying its orientation and the number of widgets per row/column (depending on the orientation
chosen via the horizontal parameter).
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Widget child)
Adds the specified widget to the end of the list of children of this container.
|
protected void |
computeContentOptimalSize(Size size)
Computes the optimal size of the widget.
|
Widget |
getCellChild(int column,
int row)
Gets the widget at the specified column and row.
|
int |
getCount()
Gets the number of widgets per row/column (depending on the grid orientation).
|
boolean |
getOrientation()
Gets the orientation of this grid.
|
void |
insertChild(Widget child,
int index)
Inserts the specified widget at the specified index in the list of children of this container.
|
protected void |
layOutChildren(int contentWidth,
int contentHeight)
Lays out the children of this container.
|
void |
removeAllChildren()
Removes all the children of this container.
|
void |
removeChild(Widget child)
Removes the specified widget from the list of children of this container.
|
void |
replaceChild(int index,
Widget child)
Replaces the child at the specified index in the list of children of this container by the specified widget.
|
void |
setCount(int count)
Sets the number of widgets per row/column (depending on the grid orientation).
|
void |
setOrientation(boolean orientation)
Sets the orientation of this grid.
|
changeChildIndex, computeChildOptimalSize, getChild, getChildIndex, getChildren, getChildrenCount, getContentBounds, getContentHeight, getContentWidth, getContentX, getContentY, getWidgetAt, layOutChild, renderChild, renderContent, setHiddenChild, setHiddenChildren, setShownChild, setShownChildren, updateStyle
addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getDesktop, getHeight, getParent, getStyle, getWidth, getX, getY, handleEvent, hasClassSelector, isAttached, isEnabled, isInState, isShown, isTransparent, onAttached, onDetached, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle
public Grid(boolean orientation, int count)
orientation
- the orientation of the grid (see LayoutOrientation
).count
- the number of widgets per row/column to set.IllegalArgumentException
- if the count is negative or zero.public void addChild(Widget child)
Container
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
addChild
in class Container
child
- the widget to add.Widget.requestLayOut()
,
Widget.isAttached()
protected void computeContentOptimalSize(Size size)
Widget
This method does not consider the border, margin, padding and dimension specified in the style.
The given size is the available size for this widget in its parent. A width or a height equal to
Widget#NO_CONSTRAINT
means that there is no constraint on this dimension.
The given size is modified to set the optimal size.
computeContentOptimalSize
in class Widget
size
- the size available for the content.public Widget getCellChild(int column, int row)
column
- the column of the widget to return.row
- the row of the widget to return.IndexOutOfBoundsException
- if the cell referenced by the given coordinates is out of range.public int getCount()
public boolean getOrientation()
LayoutOrientation
).public void insertChild(Widget child, int index)
Container
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
insertChild
in class Container
child
- the widget to add.index
- the index at which the widget should be inserted.Widget.requestLayOut()
,
Widget.isAttached()
protected void layOutChildren(int contentWidth, int contentHeight)
Container
The given size is the size of this container minus the border, margin and padding specified in the style.
When this method returns the children of this container have been lay out using
Container.layOutChild(Widget, int, int, int, int)
.
layOutChildren
in class Container
contentWidth
- the width available for the content.contentHeight
- the height available for the content.public void removeAllChildren()
Container
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
removeAllChildren
in class Container
Widget.requestLayOut()
public void removeChild(Widget child)
Container
The container needs to be laid out again.
If the widget is not in the list of children of the container, nothing is done.
Should be called in the display thread to avoid concurrency issues.
removeChild
in class Container
child
- the widget to remove.Widget.requestLayOut()
public void replaceChild(int index, Widget child)
Container
If the specified widget is already the child at the specified index of the list of children, nothing is done.
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
replaceChild
in class Container
index
- the index of the child to replace.child
- the widget to add.Widget.requestLayOut()
,
Widget.isAttached()
public void setCount(int count)
count
- the number of widgets per row/column to set.IllegalArgumentException
- if the count is negative or zero.public void setOrientation(boolean orientation)
orientation
- the orientation to set (see LayoutOrientation
).