Class BorderLayout
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 com.codename1.ui.Container class explicitly blocks
scrolling on a BorderLayout.
Typical usage of this class:
Form hi = new Form("Border Layout", new BorderLayout());
hi.add(BorderLayout.CENTER, new Label("Center")).
add(BorderLayout.SOUTH, new Label("South")).
add(BorderLayout.NORTH, new Label("North")).
add(BorderLayout.EAST, new Label("East")).
add(BorderLayout.WEST, new Label("West"));
hi.show();
When defining the center behavior we can get very different results:
Form hi = new Form("Border Layout", new BorderLayout());
((BorderLayout)hi.getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER);
hi.add(BorderLayout.CENTER, new Label("Center")).
add(BorderLayout.SOUTH, new Label("South")).
add(BorderLayout.NORTH, new Label("North")).
add(BorderLayout.EAST, new Label("East")).
add(BorderLayout.WEST, new Label("West"));
hi.show();
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe center layout constraint (middle of container)static final intDefines 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 final intDefines the behavior of the component placed in the center position of the layout, places the component in the center of the surrounding containerstatic final intDefines the behavior of the component placed in the center position of the layout, by default it is scaled to the available spacestatic final intDeprecated due to spelling mistake, use CENTER_BEHAVIOR_TOTAL_BELOW The center component takes up the entire screens and the sides are automatically placed on top of it thus creating a layered effectstatic final intThe 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 effectstatic final StringThe east layout constraint (right of container).static final StringThe north layout constraint (top of container).static final StringOverlay on top of the other layout componentsstatic final StringThe south layout constraint (bottom of container).static final StringThe west layout constraint (left of container). -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of BorderLayoutBorderLayout(int behavior) Creates a new instance of BorderLayout with absolute behavior -
Method Summary
Modifier and TypeMethodDescriptionstatic BorderLayoutabsolute()Shorthand fornew BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE)voidaddLayoutComponent(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 BorderLayoutcenter()Shorthand fornew BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER)static ContainerConvenience method that creates a border layout container and places the given component in the centerstatic ContainercenterAbsolute(Component center) Convenience method that creates a border layout container and places the given component in the center with the#CENTER_BEHAVIOR_CENTER_ABSOLUTEconstraint appliedstatic ContainercenterAbsoluteEastWest(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 respectivelystatic ContainercenterCenter(Component center) Convenience method that creates a border layout container and places the given component in the center with the#CENTER_BEHAVIOR_CENTERconstraint appliedstatic ContainercenterCenterEastWest(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_CENTERconstraint appliedstatic ContainercenterEastWest(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 respectivelystatic ContainercenterTotalBelow(Component center) Convenience method that creates a border layout container and places the given component in the center with the#CENTER_BEHAVIOR_TOTAL_BELOWconstraint appliedstatic ContainercenterTotalBelowEastWest(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_BELOWconstraint appliedvoiddefineLandscapeSwap(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 ContainerConvenience method that creates a border layout container and places the given component in the eastbooleanReturns the component in the center locationintDefines the behavior of the center component to one of the constants defined in this classprotected Component[]getChildrenInTraversalOrder(Container parent) Gets the children of the parent container in the order that they should be traversed when tabbing through a form.Returns the component constraintgetEast()Returns the component in the east locationgetLandscapeSwap(String portraitPosition) Returns the landscape swap destination for the given border layout element if such a destination is defined.getNorth()Returns the component in the north locationReturns overlay component.getPreferredSize(Container parent) Returns the container preferred sizegetSouth()Returns the component in the south locationgetWest()Returns the component in the west locationinthashCode()booleanIndicates that the center shouldn't grow and should be placed exactly in the center of the layoutbooleanIf this method returns true, the addLayoutComponent method will be called when replacing a layout for every component within the containerbooleanThis method returns true if the Layout allows Components to Overlap.booleanStretches the edge components (NORTH/EAST/WEST/SOUTH)voidlayoutContainer(Container target) Layout the given parent container childrenstatic ContainerConvenience method that creates a border layout container and places the given component in the northbooleanobscuresPotential(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.booleanoverridesTabIndices(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#getChildrenInTraversalOrder(com.codename1.ui.Container)to set the tab indices of a container's children.voidRemoves the component from the layout this operation is only useful if the layout maintains references to components within itvoidsetAbsoluteCenter(boolean absoluteCenter) Indicates that the center shouldn't grow and should be placed exactly in the center of the layoutvoidsetCenterBehavior(int centerBehavior) Defines the behavior of the center component to one of the constants defined in this classvoidsetScaleEdges(boolean scaleEdges) Stretches the edge components (NORTH/EAST/WEST/SOUTH)static ContainerConvenience method that creates a border layout container and places the given component in the southtoString()static BorderLayoutShorthand fornew BorderLayout(BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW)static ContainerConvenience method that creates a border layout container and places the given component in the westMethods inherited from class Layout
cloneConstraint, updateTabIndices
-
Field Details
-
CENTER_BEHAVIOR_SCALE
public static final int CENTER_BEHAVIOR_SCALEDefines the behavior of the component placed in the center position of the layout, by default it is scaled to the available space- See Also:
-
CENTER_BEHAVIOR_CENTER
public static final int CENTER_BEHAVIOR_CENTERDefines 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.- See Also:
-
CENTER_BEHAVIOR_CENTER_ABSOLUTE
public static final int CENTER_BEHAVIOR_CENTER_ABSOLUTEDefines the behavior of the component placed in the center position of the layout, places the component in the center of the surrounding container- See Also:
-
CENTER_BEHAVIOR_TOTAL_BELLOW
public static final int CENTER_BEHAVIOR_TOTAL_BELLOWDeprecated due to spelling mistake, use CENTER_BEHAVIOR_TOTAL_BELOW The center component takes up the entire screens and the sides are automatically placed on top of it thus creating a layered effect
Deprecated
Deprecated due to spelling mistake, use CENTER_BEHAVIOR_TOTAL_BELOW
- See Also:
-
CENTER_BEHAVIOR_TOTAL_BELOW
public static final int CENTER_BEHAVIOR_TOTAL_BELOWThe 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- See Also:
-
NORTH
-
SOUTH
-
CENTER
-
WEST
-
EAST
-
OVERLAY
-
-
Constructor Details
-
BorderLayout
public BorderLayout()Creates a new instance of BorderLayout -
BorderLayout
public BorderLayout(int behavior) Creates a new instance of BorderLayout with absolute behavior
Parameters
behavior: identical value as the setCenterBehavior method
-
-
Method Details
-
center
Shorthand for
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER)Returns
a new
BorderLayoutwith#CENTER_BEHAVIOR_CENTERconstraint applied -
absolute
Shorthand for
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE)Returns
a new
BorderLayoutwith#CENTER_BEHAVIOR_CENTER_ABSOLUTEconstraint applied -
totalBelow
Shorthand for
new BorderLayout(BorderLayout.CENTER_BEHAVIOR_TOTAL_BELOW)Returns
a new
BorderLayoutwith#CENTER_BEHAVIOR_TOTAL_BELOWconstraint applied -
center
-
centerEastWest
Convenience method that creates a border layout container and places the given component in the center east and west respectively
Parameters
-
center: the center component -
east: component or null to ignore -
west: component or null to ignore
Returns
the created component
-
-
centerAbsoluteEastWest
Convenience method that creates a border layout absolute center container and places the given component in the center east and west respectively
Parameters
-
center: the center component -
east: component or null to ignore -
west: component or null to ignore
Returns
the created component
-
-
centerCenterEastWest
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_CENTERconstraint appliedParameters
-
center: the center component -
east: component or null to ignore -
west: component or null to ignore
Returns
the created component
-
-
centerTotalBelowEastWest
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_BELOWconstraint appliedParameters
-
center: the center component -
east: component or null to ignore -
west: component or null to ignore
Returns
the created component
-
-
centerCenter
-
centerAbsolute
-
centerTotalBelow
-
north
-
south
-
east
-
west
-
addLayoutComponent
Some layouts can optionally track the addition of elements with meta-data that allows the user to "hint" on object positioning.
Parameters
-
value: optional meta data information, like alignment orientation -
comp: the added component to the layout -
c: the parent container
- Overrides:
addLayoutComponentin classLayout
-
-
removeLayoutComponent
Removes the component from the layout this operation is only useful if the layout maintains references to components within it
Parameters
comp: the removed component from layout
- Overrides:
removeLayoutComponentin classLayout
-
getComponentConstraint
Returns the component constraint
Parameters
comp: the component whose constraint is queried
Returns
one of the constraints defined in this class
- Overrides:
getComponentConstraintin classLayout
-
layoutContainer
Layout the given parent container children
Parameters
parent: the given parent container
- Specified by:
layoutContainerin classLayout
-
getPreferredSize
Returns the container preferred size
Parameters
parent: the parent container
Returns
the container preferred size
- Specified by:
getPreferredSizein classLayout
-
getSouth
Returns the component in the south location
Returns
the component in the constraint
-
getCenter
Returns the component in the center location
Returns
the component in the constraint
-
getNorth
Returns the component in the north location
Returns
the component in the constraint
-
getEast
Returns the component in the east location
Returns
the component in the constraint
-
getWest
Returns the component in the west location
Returns
the component in the constraint
-
getOverlay
Returns overlay component.
Returns
The overlay component.
-
toString
-
defineLandscapeSwap
This method allows swapping positions within the border layout when the layout orientation changes to landscape or if the layout starts off as landscape.
Parameters
-
portraitPosition: @param 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 landscape
-
-
getLandscapeSwap
Returns the landscape swap destination for the given border layout element if such a destination is defined.
Parameters
portraitPosition: the constraint used when placing the component
Returns
the constraint to use when in landscape or null if undefined
-
equals
-
hashCode
-
isAbsoluteCenter
public boolean isAbsoluteCenter()Indicates that the center shouldn't grow and should be placed exactly in the center of the layout
Returns
the absoluteCenter
Deprecated
use center behavior instead
-
setAbsoluteCenter
public void setAbsoluteCenter(boolean absoluteCenter) Indicates that the center shouldn't grow and should be placed exactly in the center of the layout
Parameters
absoluteCenter: the absoluteCenter to set
Deprecated
use center behavior instead
-
getCenterBehavior
public int getCenterBehavior()Defines the behavior of the center component to one of the constants defined in this class
Returns
the centerBehavior
-
setCenterBehavior
public void setCenterBehavior(int centerBehavior) Defines the behavior of the center component to one of the constants defined in this class
Parameters
centerBehavior: the centerBehavior to set
-
isOverlapSupported
public boolean isOverlapSupported()This method returns true if the Layout allows Components to Overlap.
Returns
true if Components may intersect in this layout
- Overrides:
isOverlapSupportedin classLayout
-
isScaleEdges
public boolean isScaleEdges()Stretches the edge components (NORTH/EAST/WEST/SOUTH)
Returns
the scaleEdges
-
setScaleEdges
public void setScaleEdges(boolean scaleEdges) Stretches the edge components (NORTH/EAST/WEST/SOUTH)
Parameters
scaleEdges: the scaleEdges to set
-
isConstraintTracking
public boolean isConstraintTracking()If this method returns true, the addLayoutComponent method will be called when replacing a layout for every component within the container
Returns
false by default
- Overrides:
isConstraintTrackingin classLayout
-
obscuresPotential
Some layout managers can obscure their child components in some cases this returns true if the basic underpinnings are in place for that. This method doesn't take padding/margin etc. into account since that is checked by the caller
Parameters
parent: parent container
Returns
true if there is a chance that this layout manager can fully obscure the background, when in doubt return false...
- Overrides:
obscuresPotentialin classLayout
-
overridesTabIndices
Description copied from class:LayoutIf 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
#getChildrenInTraversalOrder(com.codename1.ui.Container)to set the tab indices of a container's children.Parameters
parent: The parent component.
Returns
True if this layout overrides tab traversal order.
- Overrides:
overridesTabIndicesin classLayout
-
getChildrenInTraversalOrder
Description copied from class:LayoutGets the children of the parent container in the order that they should be traversed when tabbing through a form.
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
#overridesTabIndices(com.codename1.ui.Container)method to return true.Parameters
parent
Returns
Array of Components in the order
- Overrides:
getChildrenInTraversalOrderin classLayout
-