public class BorderLayout extends Layout
A border layout lays out a container, arranging and resizing its components to fit in five regions: north, south, east, west, and center. Each region may contain no more than one component, and is identified by a corresponding constant: NORTH, SOUTH, EAST, WEST, and CENTER. When adding a component to a container with a border layout, use one of these five constants.
The border layout scales all of the components within it to match the available
constraints. The NORTH & SOUTH components use their preferred height but
are stretched to take up the full width available. The EAST & WEST do the same
for the reverse axis however they leave room for the NORTH/SOUTH entries if they
are defined.
The CENTER constraint will take up the rest of the available space regardless of its preferred
size. This is normally very useful, however in some cases we would prefer that the center
component will actually position itself in the middle of the available space. For this we have
the setCenterBehavior
method.
Because of its scaling behavior scrolling a border layout makes no sense. However it is a
common mistake to apply a border layout to a scrollable container or trying to make a border
layout scrollable. That is why the Container
class explicitly blocks
scrolling on a BorderLayout.
Typical usage of this class:
When defining the center behavior we can get very different results:
Notice that in the case of RTL (right to left language also known as bidi) the EAST and WEST values are implicitly reversed as shown in this image:
You can read further in the BorderLayout section in the developer guide.
Modifier and Type | Field and Description |
---|---|
static String |
CENTER
The center layout constraint (middle of container)
|
static int |
CENTER_BEHAVIOR_CENTER
Defines the behavior of the component placed in the center position of the layout, places the component in the center of
the space available to the center component.
|
static int |
CENTER_BEHAVIOR_CENTER_ABSOLUTE
Defines the behavior of the component placed in the center position of the layout, places the component in the center of
the surrounding container
|
static int |
CENTER_BEHAVIOR_SCALE
Defines the behavior of the component placed in the center position of the layout, by default it is scaled to the available space
|
static int |
CENTER_BEHAVIOR_TOTAL_BELLOW
Deprecated.
Deprecated due to spelling mistake, use CENTER_BEHAVIOR_TOTAL_BELOW
|
static int |
CENTER_BEHAVIOR_TOTAL_BELOW
The center component takes up the entire screens and the sides are
automatically placed on top (or below based on z-order) thus creating
a layered effect
|
static String |
EAST
The east layout constraint (right of container).
|
static String |
NORTH
The north layout constraint (top of container).
|
static String |
OVERLAY
Overlay on top of the other layout components
|
static String |
SOUTH
The south layout constraint (bottom of container).
|
static String |
WEST
The west layout constraint (left of container).
|
Constructor and Description |
---|
BorderLayout()
Creates a new instance of BorderLayout
|
BorderLayout(int behavior)
Creates a new instance of BorderLayout with absolute behavior
|
Modifier and Type | Method and Description |
---|---|
static BorderLayout |
absolute()
Shorthand for
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE) |
void |
addLayoutComponent(Object name,
Component comp,
Container c)
Some layouts can optionally track the addition of elements with meta-data
that allows the user to "hint" on object positioning.
|
static BorderLayout |
center()
Shorthand for
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER) |
static Container |
center(Component center)
Convenience method that creates a border layout container and places the given component in the center
|
static Container |
centerAbsolute(Component center)
Convenience method that creates a border layout container and places the given component in the center
with the
CENTER_BEHAVIOR_CENTER_ABSOLUTE constraint applied |
static Container |
centerAbsoluteEastWest(Component center,
Component east,
Component west)
Convenience method that creates a border layout absolute center container and places the given component in the center
east and west respectively
|
static Container |
centerCenter(Component center)
Convenience method that creates a border layout container and places the given component in the center
with the
CENTER_BEHAVIOR_CENTER constraint applied |
static Container |
centerCenterEastWest(Component center,
Component east,
Component west)
Convenience method that creates a border layout center container and places the given component in the center
east and west respectively with the
CENTER_BEHAVIOR_CENTER constraint applied |
static Container |
centerEastWest(Component center,
Component east,
Component west)
Convenience method that creates a border layout container and places the given component in the center
east and west respectively
|
static Container |
centerTotalBelow(Component center)
Convenience method that creates a border layout container and places the given component in the center
with the
CENTER_BEHAVIOR_TOTAL_BELOW constraint applied |
static Container |
centerTotalBelowEastWest(Component center,
Component east,
Component west)
Convenience method that creates a border layout center container and places the given component in the center
east and west respectively with the
CENTER_BEHAVIOR_TOTAL_BELOW constraint applied |
void |
defineLandscapeSwap(String portraitPosition,
String landscapePosition)
This method allows swapping positions within the border layout when the layout
orientation changes to landscape or if the layout starts off as landscape.
|
static Container |
east(Component east)
Convenience method that creates a border layout container and places the given component in the east
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
Component |
getCenter()
Returns the component in the center location
|
int |
getCenterBehavior()
Defines the behavior of the center component to one of the constants defined in this class
|
protected Component[] |
getChildrenInTraversalOrder(Container parent)
Gets the children of the parent container in the order that they should
be traversed when tabbing through a form.
|
Object |
getComponentConstraint(Component comp)
Returns the component constraint
|
Component |
getEast()
Returns the component in the east location
|
String |
getLandscapeSwap(String portraitPosition)
Returns the landscape swap destination for the given border layout element if such
a destination is defined.
|
Component |
getNorth()
Returns the component in the north location
|
Component |
getOverlay()
Returns overlay component.
|
Dimension |
getPreferredSize(Container parent)
Returns the container preferred size
|
Component |
getSouth()
Returns the component in the south location
|
Component |
getWest()
Returns the component in the west location
|
boolean |
isAbsoluteCenter()
Deprecated.
use center behavior instead
|
boolean |
isConstraintTracking()
If this method returns true, the addLayoutComponent method will be called when replacing a
layout for every component within the container
|
boolean |
isOverlapSupported()
This method returns true if the Layout allows Components to
Overlap.
|
boolean |
isScaleEdges()
Stretches the edge components (NORTH/EAST/WEST/SOUTH)
|
void |
layoutContainer(Container target)
Layout the given parent container children
|
static Container |
north(Component north)
Convenience method that creates a border layout container and places the given component in the north
|
boolean |
obscuresPotential(Container parent)
Some layout managers can obscure their child components in some cases this
returns true if the basic underpinnings are in place for that.
|
boolean |
overridesTabIndices(Container parent)
If a layout specifies a different traversal order of its components than the
component index, then it should override this method to return true, and
it should also override
Layout.getChildrenInTraversalOrder(com.codename1.ui.Container)
to set the tab indices of a container's children. |
void |
removeLayoutComponent(Component comp)
Removes the component from the layout this operation is only useful if the
layout maintains references to components within it
|
void |
setAbsoluteCenter(boolean absoluteCenter)
Deprecated.
use center behavior instead
|
void |
setCenterBehavior(int centerBehavior)
Defines the behavior of the center component to one of the constants defined in this class
|
void |
setScaleEdges(boolean scaleEdges)
Stretches the edge components (NORTH/EAST/WEST/SOUTH)
|
static Container |
south(Component south)
Convenience method that creates a border layout container and places the given component in the south
|
String |
toString()
Returns a string representation of the object.
|
static BorderLayout |
totalBelow()
Shorthand for
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW) |
static Container |
west(Component west)
Convenience method that creates a border layout container and places the given component in the west
|
cloneConstraint, hashCode, updateTabIndices
public static final int CENTER_BEHAVIOR_SCALE
public static final int CENTER_BEHAVIOR_CENTER
public static final int CENTER_BEHAVIOR_CENTER_ABSOLUTE
public static final int CENTER_BEHAVIOR_TOTAL_BELLOW
public static final int CENTER_BEHAVIOR_TOTAL_BELOW
public static final String NORTH
public static final String SOUTH
public static final String CENTER
public static final String WEST
public static final String EAST
public static final String OVERLAY
public BorderLayout()
public BorderLayout(int behavior)
behavior
- identical value as the setCenterBehavior methodpublic static BorderLayout center()
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER)
BorderLayout
with CENTER_BEHAVIOR_CENTER
constraint appliedpublic static BorderLayout absolute()
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE)
BorderLayout
with CENTER_BEHAVIOR_CENTER_ABSOLUTE
constraint appliedpublic static BorderLayout totalBelow()
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW)
BorderLayout
with CENTER_BEHAVIOR_TOTAL_BELOW
constraint appliedpublic void addLayoutComponent(Object name, Component comp, Container c)
addLayoutComponent
in class Layout
name
- optional meta data information, like alignment orientationcomp
- the added component to the layoutc
- the parent containerpublic void removeLayoutComponent(Component comp)
removeLayoutComponent
in class Layout
comp
- the removed component from layoutpublic Object getComponentConstraint(Component comp)
getComponentConstraint
in class Layout
comp
- the component whose constraint is queriedpublic void layoutContainer(Container target)
layoutContainer
in class Layout
target
- the given parent containerpublic Dimension getPreferredSize(Container parent)
getPreferredSize
in class Layout
parent
- the parent containerpublic Component getSouth()
public Component getCenter()
public Component getNorth()
public Component getEast()
public Component getWest()
public Component getOverlay()
public String toString()
public void defineLandscapeSwap(String portraitPosition, String landscapePosition)
portraitPosition
- the position for the component when in portrait (this position
should always be used when adding a component to the layout). One of NORTH/SOUTH/EAST/WEST/CENTER.landscapePosition
- the destination position to use in landscapepublic String getLandscapeSwap(String portraitPosition)
portraitPosition
- the constraint used when placing the componentpublic boolean equals(Object o)
public boolean isAbsoluteCenter()
public void setAbsoluteCenter(boolean absoluteCenter)
absoluteCenter
- the absoluteCenter to setpublic int getCenterBehavior()
public void setCenterBehavior(int centerBehavior)
centerBehavior
- the centerBehavior to setpublic boolean isOverlapSupported()
isOverlapSupported
in class Layout
public boolean isScaleEdges()
public void setScaleEdges(boolean scaleEdges)
scaleEdges
- the scaleEdges to setpublic boolean isConstraintTracking()
isConstraintTracking
in class Layout
public boolean obscuresPotential(Container parent)
obscuresPotential
in class Layout
parent
- parent containerpublic static Container center(Component center)
center
- the center componentpublic static Container centerEastWest(Component center, Component east, Component west)
center
- the center componenteast
- component or null to ignorewest
- component or null to ignorepublic static Container centerAbsoluteEastWest(Component center, Component east, Component west)
center
- the center componenteast
- component or null to ignorewest
- component or null to ignorepublic static Container centerCenterEastWest(Component center, Component east, Component west)
CENTER_BEHAVIOR_CENTER
constraint appliedcenter
- the center componenteast
- component or null to ignorewest
- component or null to ignorepublic static Container centerTotalBelowEastWest(Component center, Component east, Component west)
CENTER_BEHAVIOR_TOTAL_BELOW
constraint appliedcenter
- the center componenteast
- component or null to ignorewest
- component or null to ignorepublic static Container centerCenter(Component center)
CENTER_BEHAVIOR_CENTER
constraint appliedcenter
- the center componentpublic static Container centerAbsolute(Component center)
CENTER_BEHAVIOR_CENTER_ABSOLUTE
constraint appliedcenter
- the center componentpublic static Container centerTotalBelow(Component center)
CENTER_BEHAVIOR_TOTAL_BELOW
constraint appliedcenter
- the center componentpublic static Container north(Component north)
north
- the north componentpublic static Container south(Component south)
south
- the south componentpublic static Container east(Component east)
east
- the east componentpublic static Container west(Component west)
west
- the west componentpublic boolean overridesTabIndices(Container parent)
Layout
Layout.getChildrenInTraversalOrder(com.codename1.ui.Container)
to set the tab indices of a container's children.overridesTabIndices
in class Layout
parent
- The parent component.protected Component[] getChildrenInTraversalOrder(Container parent)
Layout
This should only be overridden if the Layout defines a different traversal order than the standard index order.
Layouts that implement this method, should override the Layout.overridesTabIndices(com.codename1.ui.Container)
method to return true.
getChildrenInTraversalOrder
in class Layout