public class LayeredLayout

  1. Object
  2. Layout
  3. LayeredLayout

The LayeredLayout places the components in order one on top of the other and sizes them all to the size of the largest component. This is useful when trying to create an overlay on top of an existing component. E.g. an “x” button to allow removing the component as shown here

The code to generate this UI is slightly complex and contains very little relevant pieces. The only truly relevant piece the last line of code:

Form hi = new Form("Layered Layout");
int w = Math.min(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
Button settingsLabel = new Button("");
Style settingsStyle = settingsLabel.getAllStyles();
settingsStyle.setFgColor(0xff);
settingsStyle.setBorder(null);
settingsStyle.setBgColor(0xff00);
settingsStyle.setBgTransparency(255);
settingsStyle.setFont(settingsLabel.getUnselectedStyle().getFont().derive(w / 3, Font.STYLE_PLAIN));
FontImage.setMaterialIcon(settingsLabel, FontImage.MATERIAL_SETTINGS);

Button close = new Button("");
close.setUIID("Container");
close.getAllStyles().setFgColor(0xff0000);
FontImage.setMaterialIcon(close, FontImage.MATERIAL_CLOSE);
hi.add(LayeredLayout.encloseIn(settingsLabel,
        FlowLayout.encloseRight(close)));
```*

We are doing three distinct things here:

.

-  We are adding a layered layout to the form.

-  We are creating a layered layout and placing two components within. This
would be the equivalent of just creating a `LayeredLaout`
`com.codename1.ui.Container` and invoking `add` twice.
.*
-  We use
https://www.codenameone.com/javadoc/com/codename1/ui/layouts/FlowLayout.html[FlowLayout]
to position the `X` close button in the right position.

A common use case for `LayeredLayout` is the iOS carousel effect which
we can achieve by combing the `LayeredLayout` with
`com.codename1.ui.Tabs`.

```java
Form hi = new Form("Swipe Tabs", new LayeredLayout());
Tabs t = new Tabs();
t.hideTabs();

Style s = UIManager.getInstance().getComponentStyle("Button");
FontImage radioEmptyImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, s);
FontImage radioFullImage = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, s);
((DefaultLookAndFeel)UIManager.getInstance().getLookAndFeel()).setRadioButtonImages(radioFullImage, radioEmptyImage, radioFullImage, radioEmptyImage);

Container container1 = BoxLayout.encloseY(new Label("Swipe the tab to see more"),
        new Label("You can put anything here"));
t.addTab("Tab1", container1);
t.addTab("Tab2", new SpanLabel("Some text directly in the tab"));

RadioButton firstTab = new RadioButton("");
RadioButton secondTab = new RadioButton("");
firstTab.setUIID("Container");
secondTab.setUIID("Container");
new ButtonGroup(firstTab, secondTab);
firstTab.setSelected(true);
Container tabsFlow = FlowLayout.encloseCenter(firstTab, secondTab);

hi.add(t);
hi.add(BorderLayout.south(tabsFlow));

t.addSelectionListener((i1, i2) -> {
    switch(i2) {
        case 0:
            if(!firstTab.isSelected()) {
                firstTab.setSelected(true);
            }
            break;
        case 1:
            if(!secondTab.isSelected()) {
                secondTab.setSelected(true);
            }
            break;
     }
});

Notice that the layered layout sizes all components to the exact same size one on top of the other. It usually requires that we use another container within; in order to position the components correctly.

Forms have a built in layered layout that you can access via getLayeredPane(), this allows you to overlay elements on top of the content pane.

The layered pane is used internally by components such as com.codename1.components.InteractionDialog, com.codename1.u./AutoCompleteTextField etc.

Warning: Placing native widgets within a layered layout is problematic due to the behavior of peer components. Sample of peer components include the com.codename1.ui.BrowserComponent, video playback etc.

Insets

This layout optionally supports insets for laying out its children. Use of insets can allow you to achieve precise placement of components while adjusting properly to screen resizing.

Insets may be either fixed or flexible. Fixed insets may be specified in pixels (#UNIT_PIXELS), millimetres (#UNIT_DIPS), or percentage (#UNIT_PERCENT). Insets may also be specified as just “auto” (#UNIT_AUTO), in which case it is considered to be flexible (it will adapt to the component size and other insets).

Insets may also be anchored to a “reference component” so that it will always be measured from that reference component.

Insets Example

Adding a button to the top right of the parent:

`Container cnt = new Container(new LayeredLayout());
LayeredLayout ll = (LayeredLayout)cnt.getLayout();
Button btn = new Button("My Button");
cnt.add(btn);
ll.setInsets(btn, "0 0 auto auto");
    // NOTE: Insets are expressed in same order as "margin" in CSS.  Clockwise starting on top.`

Changing top inset to 2mm, and right inset to 1mm:

`ll.setInsets(btn, "2mm 1mm auto auto");`

Using percentage insets:

`ll.setInsets(btn, "25% 25% auto auto");`

NOTE: When using percent units, the percentage is always in terms of the “reference box” of the component. The “reference box” is the bounding rectangle from which the insets are measured. If none of the insets is anchored to a reference component, then the bounding box will simply be the inner bounds of the parent container (i.e. the bounds of the inside padding in the container.

Using “auto” insets

An “auto” inset is an inset that is flexible. If all 4 insets are set to auto, then the component will tend to the centre of the parent component, and its size will be the component’s preferred size (though the size will be bounded by the size of the component’s reference box). If one inset is fixed, and the opposite inset is “auto”, then the fixed inset and the component’s preferred size will dictate the' calculated size of the inset.

Reference Components

Insets may also have reference componnents. E.g. If you want a button to be anchored to the right side of a search field, you could make the button’s left inset “reference” the text field. This would be achieved as follows:

`Container cnt = new Container(new LayeredLayout());
LayeredLayout ll = (LayeredLayout)cnt.getLayout();
TextField searchField = new TextField();
Button btn = new Button("Search");
cnt.add(searchField).add(btn);
ll
  .setInsets(searchField, "1mm auto auto auto")
  .setInsets(btn, "0 auto auto 0")
  .setReferenceComponentLeft(btn, searchField, 1f)
  .setReferenceComponentTop(btn, searchField, 0);`

In the above example we set the search field to be anchored to the top of its parent (1mm inset), but for all other insets to be auto. This will result it being centered horizontally in its parent. We then anchor the button to the left and top of the search field so that the top and left insets of button will always be calculated relative to the position of searchField. In particular since the button has top and left insets of 0, the button will always be placed just to the right of the search field, with its top edge aligned with the top edge of search field.

Reference Positions

The second parameter of setReferenceComponentLeft(btn, searchField, 1f) is the reference position and it dictates which edge of the reference component (searchField) the inset should be anchored to. A value of 1 indicates that it should anchor to the opposite side of the inset (e.g. in this case it is the “left” inset we are setting, so the 1 value dictates that it is anchored to the “right” side of the text field. A value of 0 indicates that it should anchor to the same side as the inset. This is why we used 0 in the subsequent call to .setReferenceComponentTop(btn, searchField, 0);, because we want to anchor the “top” inset of button to the “top” edge of searchField.

Nested types

class LayeredLayout.LayeredLayoutConstraintA class that encapsulates the insets for a component in layered layout.

Fields

public static final byte UNIT_DIPS = 2Unit used for insets.
public static final byte UNIT_PIXELS = 0Unit used for insets.
public static final byte UNIT_PERCENT = 1Unit used for insets.
public static final byte UNIT_AUTO = 100Unit used for insets.
public static final byte UNIT_BASELINE = 101Unit used for insets.

Constructors

public LayeredLayout()

Methods

public static Container encloseIn(Component... cmps)Shorthand for Container.encloseIn(new LayeredLayout(), cmps);
public void setPreferredSizeMM(float width, float height)Sets the preferred size of this layout in MM.
public float getPreferredHeightMM()The preferred height in MM of this layout which serves as a sort of minimum height even when the components in the layout don’t demand space.
public void setPreferredHeightMM(float mm)Sets the preferred height of this layout in MM.
public float getPreferredWidthMM()The preferred width (in MM) of this layout which serves as a sort of minimum width even when the components in the layout don’t demand space.
public void setPreferredWidthMM(float mm)Sets the preferred width of this layout in MM.
public void addLayoutComponent(Object value, 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.
public LayeredLayout.LayeredLayoutConstraint getLayeredLayoutConstraint(Component cmp)Wraps #getComponentConstraint(com.codename1.ui.Component) and casts it directly to LayeredLayoutConstraint.
public Object cloneConstraint(Object constraint)Makes a copy of the given constraint.
public Object getComponentConstraint(Component comp)Gets the LayeredLayoutConstraint associated with the given component.
public LayeredLayout.LayeredLayoutConstraint createConstraint(String constraint)Creates a default layered layout constraint.
public LayeredLayout.LayeredLayoutConstraint getOrCreateConstraint(Component cmp)If the given component already has a LayeredLayoutConstraint, then this will return it.
public LayeredLayout.LayeredLayoutConstraint.Inset getInset(Component cmp, int side)Gets an Inset associated with the provided component
public String getInsetsAsString(Component cmp, boolean withLabels)Returns the insets for the given component as a string.
public String getTopInsetAsString(Component cmp)Gets the top inset as a string.
public String getBottomInsetAsString(Component cmp)Gets the bottom inset as a string.
public String getLeftInsetAsString(Component cmp)Gets the left inset as a string.
public String getRightInsetAsString(Component cmp)Gets the right inset as a string.
public LayeredLayout setInsets(Component cmp, String insets)Sets the insets for the component cmp to the values specified in insets.
public LayeredLayout setInsetTop(Component cmp, String inset)Sets the top inset for this component to the prescribed value.
public LayeredLayout setInsetBottom(Component cmp, String inset)Sets the top inset for this component to the prescribed value.
public LayeredLayout setInsetLeft(Component cmp, String inset)Sets the left inset for this component to the prescribed value.
public LayeredLayout setInsetRight(Component cmp, String inset)Sets the right inset for this component to the prescribed value.
public LayeredLayout setReferenceComponents(Component cmp, Component... referenceComponents)Sets the reference components for the insets of cmp.
public LayeredLayout setReferenceComponents(Component cmp, String refs)Sets the reference components for this component as a string of 1 to 4 component indices separated by spaces.
public LayeredLayout setReferenceComponentTop(Component cmp, Component referenceComponent)Sets the reference component for the top inset of the given component.
public LayeredLayout setReferenceComponentBottom(Component cmp, Component referenceComponent)Sets the reference component for the bottom inset of the given component.
public LayeredLayout setReferenceComponentLeft(Component cmp, Component referenceComponent)Sets the reference component for the left inset of the given component.
public LayeredLayout setReferenceComponentRight(Component cmp, Component referenceComponent)Sets the reference component for the right inset of the given component.
public LayeredLayout setReferencePositions(Component cmp, float... referencePositions)Sets the reference positions for reference components.
public LayeredLayout setReferencePositions(Component cmp, String positions)Sets the reference positions for reference components.
public LayeredLayout setReferencePositionTop(Component cmp, float position)Sets the top inset reference position.
public LayeredLayout setReferenceComponentTop(Component cmp, Component referenceComponent, float position)Sets the reference component for the top inset of the given component.
public LayeredLayout setReferencePositionBottom(Component cmp, float position)Sets the bottom inset reference position.
public LayeredLayout setReferenceComponentBottom(Component cmp, Component referenceComponent, float position)Sets the reference component for the bottom inset of the given component.
public LayeredLayout setReferencePositionLeft(Component cmp, float position)Sets the left inset reference position.
public LayeredLayout setReferenceComponentLeft(Component cmp, Component referenceComponent, float position)Sets the reference component for the left inset of the given component.
public LayeredLayout setReferencePositionRight(Component cmp, float position)Sets the right inset reference position.
public LayeredLayout setReferenceComponentRight(Component cmp, Component referenceComponent, float position)Sets the reference component for the right inset of the given component.
public LayeredLayout setPercentInsetAnchorHorizontal(Component cmp, float anchor)See LayeredLayoutConstraint#setPercentInsetAnchorHorizontal(float)
public LayeredLayout setPercentInsetAnchorVertical(Component cmp, float anchor)See LayeredLayoutConstraint#setPercentInsetAnchorVertical(float)
public float getPercentInsetAnchorHorizontal(Component cmp)See LayeredLayoutConstraint#getPercentInsetAnchorHorizontal()
public float getPercentInsetAnchorVertical(Component cmp)See LayeredLayoutConstraint#getPercentInsetAnchorVertical()
public void layoutContainer(Container parent)Layout the given parent container children
public Dimension getPreferredSize(Container parent)Returns the container preferred size
public String toString()Returns a string representation of the object.
public boolean isOverlapSupported()This method returns true if the Layout allows Components to Overlap.
public 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.
public LayeredLayout.LayeredLayoutConstraint createConstraint()Creates a new LayeredLayoutConstraint
public 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 #getChildrenInTraversalOrder(com.codename1.ui.Container) to set the tab indices of a container’s children.
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.

Inherited methods

Field details

UNIT_DIPS

public static final byte UNIT_DIPS = 2
Unit used for insets. Millimetres.

UNIT_PIXELS

public static final byte UNIT_PIXELS = 0
Unit used for insets. Pixels.

UNIT_PERCENT

public static final byte UNIT_PERCENT = 1
Unit used for insets. Percent.

UNIT_AUTO

public static final byte UNIT_AUTO = 100
Unit used for insets. Auto. Auto unit type for an inset indicates the the inset will be automatically determined at layout time.

UNIT_BASELINE

public static final byte UNIT_BASELINE = 101
Unit used for insets. Baseline. Baseline unit type for an inset indicates the inset will be aligned with the baseline of the reference component. This only makes sense for the top inset. The height will automatically become the preferred height and the bottom inset will become “auto” if the top inset uses the baseline unit.

Constructor details

LayeredLayout

public LayeredLayout()

Method details

encloseIn

public static Container encloseIn(Component... cmps)
Shorthand for Container.encloseIn(new LayeredLayout(), cmps);

Parameters

cmps Component...
the components to add to a new layered layout container

Returns

a newly created layered layout

setPreferredSizeMM

public void setPreferredSizeMM(float width, float height)
Sets the preferred size of this layout in MM. This serves as a minimum size that will be returned by calcPreferredSize().

Parameters

width float
The preferred width in MM.
height float
The preferred height in MM.

getPreferredHeightMM

public float getPreferredHeightMM()

The preferred height in MM of this layout which serves as a sort of minimum height even when the components in the layout don’t demand space.

The actual preferred height will be the max of this value and the calculated preferred height based on the container’s children.

setPreferredHeightMM

public void setPreferredHeightMM(float mm)
Sets the preferred height of this layout in MM.

getPreferredWidthMM

public float getPreferredWidthMM()

The preferred width (in MM) of this layout which serves as a sort of minimum width even when the components in the layout don’t demand space.

The actual preferred width will be the max of this value and the calculated preferred width based on the container’s children.

setPreferredWidthMM

public void setPreferredWidthMM(float mm)
Sets the preferred width of this layout in MM.

addLayoutComponent

public void addLayoutComponent(Object value, 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.

Parameters

value Object
optional meta data information, like alignment orientation
comp Component
the added component to the layout
c Container
the parent container

getLayeredLayoutConstraint

public LayeredLayout.LayeredLayoutConstraint getLayeredLayoutConstraint(Component cmp)
Wraps #getComponentConstraint(com.codename1.ui.Component) and casts it directly to LayeredLayoutConstraint.

Parameters

cmp Component
The component whose constraint we want to retrieve.

Returns

The layered layout constraint for this component.

cloneConstraint

public Object cloneConstraint(Object constraint)
Makes a copy of the given constraint.

Parameters

constraint Object
The constraint to copy.

Returns

The copied constraint.

getComponentConstraint

public Object getComponentConstraint(Component comp)

Gets the LayeredLayoutConstraint associated with the given component.

May return null if there is no constraint.

Returns

the optional component constraint

createConstraint

public LayeredLayout.LayeredLayoutConstraint createConstraint(String constraint)
Creates a default layered layout constraint. Default constraint has zero insets on all four sides.

getOrCreateConstraint

public LayeredLayout.LayeredLayoutConstraint getOrCreateConstraint(Component cmp)
If the given component already has a LayeredLayoutConstraint, then this will return it. Otherwise it will create a constraint, install it in cmp and return the constraint for inspection or manipulation.

Parameters

cmp Component
The component whose constraint we wish to retrieve.

Returns

The constraint for a given component.

getInset

public LayeredLayout.LayeredLayoutConstraint.Inset getInset(Component cmp, int side)
Gets an Inset associated with the provided component

Parameters

cmp Component
The component whose inset we wish to retrieve.
side int
The side of the inset. One of Component#TOP, Component#LEFT, Component#BOTTOM or Component#RIGHT.

Returns

The Inset for the given side of the component.

getInsetsAsString

public String getInsetsAsString(Component cmp, boolean withLabels)
Returns the insets for the given component as a string. This can return the insets in one of two formats depending on the value of the withLabels parameter.

Parameters

cmp Component
The component whose insets we wish to retrieve.
withLabels boolean
If false, then this returns a string of the format "top right bottom left" e.g "2mm 2mm 2mm 2mm". If true, then it will be formatted like CSS properties: "top:2mm; right:2mm; bottom:2mm; left:2mm".

Returns

The insets associated with cmp as a string. Each inset will include the unit. E.g.:

  • 2mm = 2 millimetres/dips
  • 2px = 2 pixels
  • 25% = 25%
  • auto = Flexible inset

getTopInsetAsString

public String getTopInsetAsString(Component cmp)

Gets the top inset as a string. Return value will include the unit, so the following are possible values:

  • 2mm = 2 millimetres

  • 2px = 2 pixels

  • 25% = 25%

  • auto = Flexible Inset

Parameters

cmp Component
The component whose inset we wish to retrieve.

Returns

The inset formatted as a string with the unit abbreviation (“mm”, “px”, or “%”) suffixed.

getBottomInsetAsString

public String getBottomInsetAsString(Component cmp)

Gets the bottom inset as a string. Return value will include the unit, so the following are possible values:

  • 2mm = 2 millimetres

  • 2px = 2 pixels

  • 25% = 25%

  • auto = Flexible Inset

Parameters

cmp Component
The component whose inset we wish to retrieve.

Returns

The inset formatted as a string with the unit abbreviation (“mm”, “px”, or “%”) suffixed.

getLeftInsetAsString

public String getLeftInsetAsString(Component cmp)

Gets the left inset as a string. Return value will include the unit, so the following are possible values:

  • 2mm = 2 millimetres

  • 2px = 2 pixels

  • 25% = 25%

  • auto = Flexible Inset

Parameters

cmp Component
The component whose inset we wish to retrieve.

Returns

The inset formatted as a string with the unit abbreviation (“mm”, “px”, or “%”) suffixed.

getRightInsetAsString

public String getRightInsetAsString(Component cmp)

Gets the right inset as a string. Return value will include the unit, so the following are possible values:

  • 2mm = 2 millimetres

  • 2px = 2 pixels

  • 25% = 25%

  • auto = Flexible Inset

Parameters

cmp Component
The component whose inset we wish to retrieve.

Returns

The inset formatted as a string with the unit abbreviation (“mm”, “px”, or “%”) suffixed.

setInsets

public LayeredLayout setInsets(Component cmp, String insets)
Sets the insets for the component cmp to the values specified in insets.

Parameters

cmp Component
The component whose insets we wish to set.
insets String
The insets expressed as a string. See LayeredLayoutConstraint#setInsets(java.lang.String) for details on the format of this parameter.

Returns

Self for chaining.

See also

setInsetTop

public LayeredLayout setInsetTop(Component cmp, String inset)
Sets the top inset for this component to the prescribed value.

Parameters

cmp Component
The component whose inset we wish to set.
inset String
The inset value, including unit. Units are Percent (%), Millimetres (mm), Pixels (px), and “auto”. E.g. the following insets values would all be acceptable:

Returns

Self for chaining.

setInsetBottom

public LayeredLayout setInsetBottom(Component cmp, String inset)
Sets the top inset for this component to the prescribed value.

Parameters

cmp Component
The component whose inset we wish to set.
inset String
The inset value, including unit. Units are Percent (%), Millimetres (mm), Pixels (px), and “auto”. E.g. the following insets values would all be acceptable:

Returns

Self for chaining.

setInsetLeft

public LayeredLayout setInsetLeft(Component cmp, String inset)
Sets the left inset for this component to the prescribed value.

Parameters

cmp Component
The component whose inset we wish to set.
inset String
The inset value, including unit. Units are Percent (%), Millimetres (mm), Pixels (px), and “auto”. E.g. the following insets values would all be acceptable:

Returns

Self for chaining.

setInsetRight

public LayeredLayout setInsetRight(Component cmp, String inset)
Sets the right inset for this component to the prescribed value.

Parameters

cmp Component
The component whose inset we wish to set.
inset String
The inset value, including unit. Units are Percent (%), Millimetres (mm), Pixels (px), and “auto”. E.g. the following insets values would all be acceptable:

Returns

Self for chaining.

setReferenceComponents

public LayeredLayout setReferenceComponents(Component cmp, Component... referenceComponents)
Sets the reference components for the insets of cmp. See LayeredLayoutConstraint#setReferenceComponents(com.codename1.ui.Component...) for a full description of the parameters.

Parameters

cmp Component
The component whose reference components we wish to check.
referenceComponents Component...
The reference components. This var arg may contain 1 to 4 values. See LayeredLayoutConstraint#setReferenceComponents(com.codename1.ui.Component...) for a full description.

Returns

Self for chaining.

setReferenceComponents

public LayeredLayout setReferenceComponents(Component cmp, String refs)
Sets the reference components for this component as a string of 1 to 4 component indices separated by spaces. An index of -1 indicates no reference for the corresponding inset. See java.lang.String) for a description of the refs parameter.

Parameters

cmp Component
The component whose references we’re setting.
refs String
Reference components as a string of component indices in the parent.

Returns

Self for chaining.

setReferenceComponentTop

public LayeredLayout setReferenceComponentTop(Component cmp, Component referenceComponent)
Sets the reference component for the top inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to anchor the inset to.

Returns

Self for chaining.

setReferenceComponentBottom

public LayeredLayout setReferenceComponentBottom(Component cmp, Component referenceComponent)
Sets the reference component for the bottom inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to anchor the inset to.

Returns

Self for chaining.

setReferenceComponentLeft

public LayeredLayout setReferenceComponentLeft(Component cmp, Component referenceComponent)
Sets the reference component for the left inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to anchor the inset to.

Returns

Self for chaining.

setReferenceComponentRight

public LayeredLayout setReferenceComponentRight(Component cmp, Component referenceComponent)
Sets the reference component for the right inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to anchor the inset to.

Returns

Self for chaining.

setReferencePositions

public LayeredLayout setReferencePositions(Component cmp, float... referencePositions)
Sets the reference positions for reference components. See LayeredLayoutConstraint#setReferencePositions(float...) for a description of the parameters.

Parameters

cmp Component
The component whose insets we are manipulating.
referencePositions float...
The reference positions for the reference components. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of this parameter.

Returns

Self for chaining.

setReferencePositions

public LayeredLayout setReferencePositions(Component cmp, String positions)
Sets the reference positions for reference components. See LayeredLayoutConstraint#setReferencePositions(float...) for a description of the parameters.

Parameters

cmp Component
The component whose insets we are manipulating.
positions String
The reference positions for the reference components. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of this parameter.

Returns

Self for chaining.

setReferencePositionTop

public LayeredLayout setReferencePositionTop(Component cmp, float position)
Sets the top inset reference position. Only applicable if the top inset has a reference component specified.

Parameters

cmp Component
The component whose insets were are manipulating.
position float
The position. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of the possible values here.

setReferenceComponentTop

public LayeredLayout setReferenceComponentTop(Component cmp, Component referenceComponent, float position)
Sets the reference component for the top inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to which the inset should be anchored.
position float
The position of the reference anchor. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of reference positions.

setReferencePositionBottom

public LayeredLayout setReferencePositionBottom(Component cmp, float position)
Sets the bottom inset reference position. Only applicable if the top inset has a reference component specified.

Parameters

cmp Component
The component whose insets were are manipulating.
position float
The position. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of the possible values here.

setReferenceComponentBottom

public LayeredLayout setReferenceComponentBottom(Component cmp, Component referenceComponent, float position)
Sets the reference component for the bottom inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to which the inset should be anchored.
position float
The position of the reference anchor. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of reference positions.

setReferencePositionLeft

public LayeredLayout setReferencePositionLeft(Component cmp, float position)
Sets the left inset reference position. Only applicable if the top inset has a reference component specified.

Parameters

cmp Component
The component whose insets were are manipulating.
position float
The position. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of the possible values here.

setReferenceComponentLeft

public LayeredLayout setReferenceComponentLeft(Component cmp, Component referenceComponent, float position)
Sets the reference component for the left inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to which the inset should be anchored.
position float
The position of the reference anchor. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of reference positions.

setReferencePositionRight

public LayeredLayout setReferencePositionRight(Component cmp, float position)
Sets the right inset reference position. Only applicable if the top inset has a reference component specified.

Parameters

cmp Component
The component whose insets were are manipulating.
position float
The position. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of the possible values here.

setReferenceComponentRight

public LayeredLayout setReferenceComponentRight(Component cmp, Component referenceComponent, float position)
Sets the reference component for the right inset of the given component.

Parameters

cmp Component
The component whose insets we are manipulating.
referenceComponent Component
The component to which the inset should be anchored.
position float
The position of the reference anchor. See LayeredLayoutConstraint#setReferencePositions(float...) for a full description of reference positions.

setPercentInsetAnchorHorizontal

public LayeredLayout setPercentInsetAnchorHorizontal(Component cmp, float anchor)
See LayeredLayoutConstraint#setPercentInsetAnchorHorizontal(float)

Returns

Self for chaining

setPercentInsetAnchorVertical

public LayeredLayout setPercentInsetAnchorVertical(Component cmp, float anchor)
See LayeredLayoutConstraint#setPercentInsetAnchorVertical(float)

Returns

Self for chaining

getPercentInsetAnchorHorizontal

public float getPercentInsetAnchorHorizontal(Component cmp)
See LayeredLayoutConstraint#getPercentInsetAnchorHorizontal()

getPercentInsetAnchorVertical

public float getPercentInsetAnchorVertical(Component cmp)
See LayeredLayoutConstraint#getPercentInsetAnchorVertical()

layoutContainer

public void layoutContainer(Container parent)
Layout the given parent container children

Parameters

parent Container
the given parent container

getPreferredSize

public Dimension getPreferredSize(Container parent)
Returns the container preferred size

Parameters

parent Container
the parent container

Returns

the container preferred size

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + ‘@’ + Integer.toHexString(hashCode())

isOverlapSupported

public boolean isOverlapSupported()
This method returns true if the Layout allows Components to Overlap.

Returns

true if Components may intersect in this layout

obscuresPotential

public 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. This method doesn’t take padding/margin etc. into account since that is checked by the caller

Parameters

parent Container
parent container

Returns

true if there is a chance that this layout manager can fully obscure the background, when in doubt return false…

createConstraint

public LayeredLayout.LayeredLayoutConstraint createConstraint()
Creates a new LayeredLayoutConstraint

overridesTabIndices

public 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 #getChildrenInTraversalOrder(com.codename1.ui.Container) to set the tab indices of a container’s children.

Parameters

parent Container
The parent component.

Returns

True if this layout overrides tab traversal order.

getChildrenInTraversalOrder

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.

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.

Returns

Array of Components in the order