public class FlowLayout extends Layout
FlowLayout is the default layout manager for Codename One Containers and Forms. It places components in a row one after another based on their preferred size. When it reaches the edge of the container it will break a line and start a new row.
Since flow layout isn't a constraint based layout it has a bunch of very useful enclose methods that can significantly reduce the code required to create the same UI e.g.:
This class works nicely for simple elements, however since Codename One doesn't reflow recursively (for performance) it can't accurately handle complex layouts. As a result when an element of varying size is placed in a flow layout this confuses the line breaking logic and fails in odd ways. That is why this layout should only be used for relatively simple use cases.
Flow layout supports aligning the component horizontally and vertically, it defaults to the top left alignment for
LTR languages. E.g. the following alignments are supported thru the usage of setAlign
&
setValign
.
E.g. you can align to the center
You can align to the right
You can align to the center and the middle horizontally
There are quite a few additional combinations that are possible with these API's.
Constructor and Description |
---|
FlowLayout()
Creates a new instance of FlowLayout with left alignment
|
FlowLayout(int orientation)
Creates a new instance of FlowLayout with the given orientation one of
LEFT, RIGHT or CENTER
|
FlowLayout(int orientation,
int valign)
Creates a new instance of FlowLayout with the given orientation one of
LEFT, RIGHT or CENTER and the vertical orientation
|
FlowLayout(int orientation,
int valign,
boolean vAlignByRow)
Creates a new instance of FlowLayout with the given orientation one of
LEFT, RIGHT or CENTER and the vertical orientation
|
Modifier and Type | Method and Description |
---|---|
static Container |
encloseBottom(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.LEFT, Component.BOTTOM), cmps);
|
static Container |
encloseBottomByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.LEFT, Component.BOTTOM, true), cmps);
|
static Container |
encloseCenter(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.CENTER), cmps);
|
static Container |
encloseCenterBottom(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.CENTER, Component.BOTTOM), cmps);
|
static Container |
encloseCenterBottomByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.CENTER, Component.BOTTOM, true), cmps);
|
static Container |
encloseCenterMiddle(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.CENTER, Component.CENTER), cmps);
|
static Container |
encloseCenterMiddleByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.CENTER, Component.CENTER, true), cmps);
|
static Container |
encloseIn(Component... cmps)
Shorthand for
Container.encloseIn(com.codename1.ui.layouts.Layout, com.codename1.ui.Component...)
with a FlowLayout instance see: |
static Container |
encloseLeftMiddle(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.LEFT, Component.CENTER), cmps);
|
static Container |
encloseLeftMiddleByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.LEFT, Component.CENTER, true), cmps);
|
static Container |
encloseMiddle(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.LEFT, Component.CENTER), cmps);
|
static Container |
encloseMiddleByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.LEFT, Component.CENTER, true), cmps);
|
static Container |
encloseRight(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.RIGHT), cmps);
|
static Container |
encloseRightBottom(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.RIGHT, Component.BOTTOM), cmps);
|
static Container |
encloseRightBottomByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.RIGHT, Component.BOTTOM, true), cmps);
|
static Container |
encloseRightMiddle(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.RIGHT, Component.CENTER), cmps);
|
static Container |
encloseRightMiddleByRow(Component... cmps)
Shorthand for Container.encloseIn(new FlowLayout(Component.RIGHT, Component.CENTER, true), cmps);
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
protected void |
fillRow(Container target,
int width,
int start,
int end)
This method tries to fill up the available space in a row.
|
int |
getAlign()
Alignment of the flow layout, defaults to LEFT
|
Dimension |
getPreferredSize(Container parent)
Returns the container preferred size
|
int |
getValign()
Indicates vertical alignment within the flow layout
|
boolean |
isFillRows()
Indicates whether the layout manager should try to fill up the available space
in the row
|
boolean |
isValignByRow()
Returns whether vertical alignment is done internally or externally
|
void |
layoutContainer(Container parent)
Layout the given parent container children
|
void |
setAlign(int orientation)
Alignment of the flow layout, defaults to LEFT
|
void |
setFillRows(boolean fillRows)
Indicates whether the layout manager should try to fill up the available space
in the row
|
void |
setValign(int valign)
Indicates vertical alignment within the flow layout
|
void |
setValignByRow(boolean internal)
When set to true vertical alignment will be performed by row (components within the container will be aligned vertically to each other in the same row)
When set to false (which is default) vertical alignment relates to the alignment of this container in regards to external components
|
String |
toString()
Returns a string representation of the object.
|
addLayoutComponent, cloneConstraint, getChildrenInTraversalOrder, getComponentConstraint, hashCode, isConstraintTracking, isOverlapSupported, obscuresPotential, overridesTabIndices, removeLayoutComponent, updateTabIndices
public FlowLayout()
public FlowLayout(int orientation)
orientation
- the orientation valuepublic FlowLayout(int orientation, int valign)
orientation
- the orientation valuevalign
- the vertical orientation one of Component.TOP/BOTTOM/CENTERpublic FlowLayout(int orientation, int valign, boolean vAlignByRow)
orientation
- the orientation valuevalign
- the vertical orientation one of Component.TOP/BOTTOM/CENTERvAlignByRow
- whether vertical alignment should be computed by row elementspublic void layoutContainer(Container parent)
layoutContainer
in class Layout
parent
- the given parent containerprotected void fillRow(Container target, int width, int start, int end)
target
- the parent containerwidth
- the width of the row to fillstart
- the index of the first component in this rowend
- the index of the last component in this rowpublic Dimension getPreferredSize(Container parent)
getPreferredSize
in class Layout
parent
- the parent containerpublic String toString()
public boolean isFillRows()
public void setFillRows(boolean fillRows)
fillRows
- the fillRows to setpublic int getValign()
public void setValign(int valign)
valign
- one of Component.TOP/BOTTOM/CENTERpublic void setValignByRow(boolean internal)
internal
- true for internal, false otherwisepublic boolean isValignByRow()
public int getAlign()
public void setAlign(int orientation)
orientation
- the orientation to setpublic boolean equals(Object o)
public static Container encloseIn(Component... cmps)
Shorthand for Container.encloseIn(com.codename1.ui.layouts.Layout, com.codename1.ui.Component...)
with a FlowLayout instance
see:
cmps
- the components to enclose in a new containerpublic static Container encloseCenter(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseRight(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseMiddle(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseMiddleByRow(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseCenterMiddle(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseCenterMiddleByRow(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseRightMiddle(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseRightMiddleByRow(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseLeftMiddle(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseLeftMiddleByRow(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseBottom(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseCenterBottom(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseRightBottom(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseBottomByRow(Component... cmps)
cmps
- the components to enclose in a new containerpublic static Container encloseCenterBottomByRow(Component... cmps)
cmps
- the components to enclose in a new container