Class Grid
- java.lang.Object
-
- ej.mwt.Widget
-
- ej.mwt.Container
-
- ej.widget.container.Grid
-
public class Grid extends Container
Lays out any number of children in a grid.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:

-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ej.mwt.Widget
Widget.WidgetListener
-
-
Field Summary
-
Fields inherited from class ej.mwt.Widget
DEBUG_WIDGET_ENABLED_CONSTANT, DEBUG_WIDGET_MONITOR_CONSTANT, NO_CONSTRAINT
-
-
Constructor Summary
Constructors Constructor 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).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(Widget child)Adds the specified widget to the end of the list of children of this container.protected voidcomputeContentOptimalSize(Size size)Computes the optimal size of the widget.WidgetgetCellChild(int column, int row)Gets the widget at the specified column and row.intgetCount()Gets the number of widgets per row/column (depending on the grid orientation).booleangetOrientation()Gets the orientation of this grid.voidinsertChild(Widget child, int index)Inserts the specified widget at the specified index in the list of children of this container.protected voidlayOutChildren(int contentWidth, int contentHeight)Lays out the children of this container.voidremoveAllChildren()Removes all the children of this container.voidremoveChild(Widget child)Removes the specified widget from the list of children of this container.voidreplaceChild(int index, Widget child)Replaces the child at the specified index in the list of children of this container by the specified widget.voidsetCount(int count)Sets the number of widgets per row/column (depending on the grid orientation).voidsetOrientation(boolean orientation)Sets the orientation of this grid.-
Methods inherited from class ej.mwt.Container
changeChildIndex, computeChildOptimalSize, getChild, getChildIndex, getChildren, getChildrenCount, getContentBounds, getContentHeight, getContentWidth, getContentX, getContentY, getWidgetAt, layOutAlignedChild, layOutChild, renderChild, renderContent, setHiddenChild, setHiddenChildren, setShownChild, setShownChildren, updateStyle
-
Methods inherited from class ej.mwt.Widget
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, setX, setY
-
-
-
-
Constructor Detail
-
Grid
public 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).- Parameters:
orientation- the orientation of the grid (seeLayoutOrientation).count- the number of widgets per row/column to set.- Throws:
IllegalArgumentException- if the count is negative or zero.
-
-
Method Detail
-
setOrientation
public void setOrientation(boolean orientation)
Sets the orientation of this grid.- Parameters:
orientation- the orientation to set (seeLayoutOrientation).
-
getOrientation
public boolean getOrientation()
Gets the orientation of this grid.- Returns:
- the orientation of this grid (see
LayoutOrientation).
-
setCount
public void setCount(int count)
Sets the number of widgets per row/column (depending on the grid orientation).- Parameters:
count- the number of widgets per row/column to set.- Throws:
IllegalArgumentException- if the count is negative or zero.
-
getCount
public int getCount()
Gets the number of widgets per row/column (depending on the grid orientation).- Returns:
- the number of widgets per row/column.
-
getCellChild
public Widget getCellChild(int column, int row)
Gets the widget at the specified column and row.- Parameters:
column- the column of the widget to return.row- the row of the widget to return.- Returns:
- the widget at the specified column and row.
- Throws:
IndexOutOfBoundsException- if the cell referenced by the given coordinates is out of range.
-
addChild
public void addChild(Widget child)
Description copied from class:ContainerAdds the specified widget to the end of the list of children of this container.The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
- Overrides:
addChildin classContainer- Parameters:
child- the widget to add.- See Also:
Widget.requestLayOut(),Widget.isAttached()
-
removeChild
public void removeChild(Widget child)
Description copied from class:ContainerRemoves the specified widget from the list of children of this 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.
- Overrides:
removeChildin classContainer- Parameters:
child- the widget to remove.- See Also:
Widget.requestLayOut()
-
insertChild
public void insertChild(Widget child, int index)
Description copied from class:ContainerInserts the specified widget at the specified index in the list of children of this container.The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
- Overrides:
insertChildin classContainer- Parameters:
child- the widget to add.index- the index at which the widget should be inserted.- See Also:
Widget.requestLayOut(),Widget.isAttached()
-
replaceChild
public void replaceChild(int index, Widget child)Description copied from class:ContainerReplaces the child at the specified index in the list of children of this container by the specified widget.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.
- Overrides:
replaceChildin classContainer- Parameters:
index- the index of the child to replace.child- the widget to add.- See Also:
Widget.requestLayOut(),Widget.isAttached()
-
removeAllChildren
public void removeAllChildren()
Description copied from class:ContainerRemoves all the children of this container.The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
- Overrides:
removeAllChildrenin classContainer- See Also:
Widget.requestLayOut()
-
computeContentOptimalSize
protected void computeContentOptimalSize(Size size)
Description copied from class:WidgetComputes the optimal size of the 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_CONSTRAINTmeans that there is no constraint on this dimension.The given size is modified to set the optimal size.
- Specified by:
computeContentOptimalSizein classWidget- Parameters:
size- the size available for the content.
-
layOutChildren
protected void layOutChildren(int contentWidth, int contentHeight)Description copied from class:ContainerLays out the children of this 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).- Specified by:
layOutChildrenin classContainer- Parameters:
contentWidth- the width available for the content.contentHeight- the height available for the content.
-
-