public class BoxLayout extends Layout
Layout manager that places elements in a row (X_AXIS
) or column (Y_AXIS
)
according to box orientation. Box is a very simple and predictable layout that serves as the "workhorse" of
component lists in Codename One
You can create a box layout Y UI using syntax such as this
This can also be expressed with more terse syntax e.g. an X axis layout like this:
The BoxLayout
keeps the preferred size of its destination orientation and scales elements on the other axis.
Specifically X_AXIS
will keep the preferred width of the component while growing all
the components vertically to match in size. Its Y_AXIS
counterpart keeps the preferred height
while growing the components horizontally.
This behavior is very useful since it allows elements to align as they would all have the same size.
In some cases the growing behavior in the X axis is undesired, for these cases we can use the X_AXIS_NO_GROW
variant.
There are quite a few differences between FlowLayout
and BoxLayout
. When it doesn't
matter to you we tend to recommend BoxLayout
as it acts more consistently in all situations since
its far simpler. Another advantage of BoxLayout
is the fact that it grows and thus aligns nicely.
Modifier and Type | Field and Description |
---|---|
static int |
X_AXIS
Horizontal layout where components are arranged from left to right
|
static int |
X_AXIS_NO_GROW
Horizontal layout where components are arranged from left to right but don't grow vertically beyond their preferred size
|
static int |
Y_AXIS
Vertical layout where components are arranged from top to bottom
|
static int |
Y_AXIS_BOTTOM_LAST
Same as Y_AXIS with a special case for the last component.
|
Constructor and Description |
---|
BoxLayout(int axis)
Creates a new instance of BoxLayout
|
Modifier and Type | Method and Description |
---|---|
static Container |
encloseX(Component... cmps)
The equivalent of Container.enclose() with a box layout X
|
static Container |
encloseXCenter(Component... cmps)
The equivalent of Container.enclose() with a box layout X, with center alignment.
|
static Container |
encloseXNoGrow(Component... cmps)
The equivalent of Container.enclose() with a box layout X no grow option
|
static Container |
encloseXRight(Component... cmps)
The equivalent of Container.enclose() with a box layout X, with right alignment.
|
static Container |
encloseY(Component... cmps)
The equivalent of Container.enclose() with a box layout Y
|
static Container |
encloseYBottom(Component... cmps)
The equivalent of Container.enclose() with a box layout Y, with bottom alignment.
|
static Container |
encloseYBottomLast(Component... cmps)
The equivalent of Container.enclose() with a box layout Y in bottom
last mode
|
static Container |
encloseYCenter(Component... cmps)
The equivalent of Container.enclose() with a box layout Y, with center alignment.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
int |
getAlign()
Gets the alignment of this layout.
|
int |
getAxis()
Returns the layout axis x/y
|
Dimension |
getPreferredSize(Container parent)
Returns the container preferred size
|
void |
layoutContainer(Container parent)
Layout the given parent container children
|
void |
setAlign(int align)
Sets the alignment of this layout.
|
String |
toString()
Returns a string representation of the object.
|
static BoxLayout |
x()
Shorthand for
new BoxLayout(BoxLayout.X_AXIS) |
static BoxLayout |
xCenter()
Creates a new layout with
X_AXIS , and align center. |
static BoxLayout |
xRight()
Creates a new layout with
X_AXIS , and align right. |
static BoxLayout |
y()
Shorthand for
new BoxLayout(BoxLayout.Y_AXIS) |
static BoxLayout |
yBottom()
Creates a new layout with
Y_AXIS , and align bottom. |
static BoxLayout |
yCenter()
Creates a new layout with
Y_AXIS , and align center. |
static BoxLayout |
yLast()
Shorthand for
new BoxLayout(BoxLayout.Y_AXIS_BOTTOM_LAST) |
addLayoutComponent, cloneConstraint, getChildrenInTraversalOrder, getComponentConstraint, hashCode, isConstraintTracking, isOverlapSupported, obscuresPotential, overridesTabIndices, removeLayoutComponent, updateTabIndices
public static final int X_AXIS
public static final int Y_AXIS
public static final int X_AXIS_NO_GROW
public static final int Y_AXIS_BOTTOM_LAST
public BoxLayout(int axis)
axis
- the axis to lay out components along.
Can be: BoxLayout.X_AXIS or BoxLayout.Y_AXISpublic static BoxLayout y()
new BoxLayout(BoxLayout.Y_AXIS)
BoxLayout
public static BoxLayout yLast()
new BoxLayout(BoxLayout.Y_AXIS_BOTTOM_LAST)
BoxLayout
public static BoxLayout yCenter()
Y_AXIS
, and align center.public static BoxLayout yBottom()
Y_AXIS
, and align bottom.public static BoxLayout x()
new BoxLayout(BoxLayout.X_AXIS)
BoxLayout
public static BoxLayout xCenter()
X_AXIS
, and align center.public static BoxLayout xRight()
X_AXIS
, and align right.public void setAlign(int align)
Component.CENTER
to align items vertically centered (for Y_AXIS), and horizontally centered (for X_AXIS),
of Component.BOTTOM
to align vertically bottom (Y_AXIS), and Component.RIGHT
to align right (RTL-aware), for X_AXIS.align
- One of Component.CENTER
, Component.BOTTOM
, Component.RIGHT
, to adjust the alignment of children.public int getAlign()
Component.CENTER
to align items vertically centered (for Y_AXIS), and horizontally centered (for X_AXIS),
of Component.BOTTOM
to align vertically bottom (Y_AXIS), and Component.RIGHT
to align right (RTL-aware), for X_AXIS.public void layoutContainer(Container parent)
layoutContainer
in class Layout
parent
- the given parent containerpublic Dimension getPreferredSize(Container parent)
getPreferredSize
in class Layout
parent
- the parent containerpublic int getAxis()
public String toString()
public boolean equals(Object o)
public static Container encloseY(Component... cmps)
cmps
- the set of componentspublic static Container encloseYCenter(Component... cmps)
cmps
- the set of componentspublic static Container encloseYBottom(Component... cmps)
cmps
- the set of componentspublic static Container encloseYBottomLast(Component... cmps)
cmps
- the set of componentspublic static Container encloseX(Component... cmps)
cmps
- the set of componentspublic static Container encloseXNoGrow(Component... cmps)
cmps
- the set of componentspublic static Container encloseXCenter(Component... cmps)
cmps
- the set of components