Class Flex


  • public class Flex
    extends ej.mwt.Container
    Lays out child elements in a flexible manner by arranging them along a main axis and a cross axis.

    The flex layout manager allows you to create flexible and responsive layouts for containers. It arranges child elements individually along the main axis, following the specified direction and justify. Additionally, you can control the alignment of the items along the cross axis. Child elements are positioned based on the order they are added to the layout.

    Example of a flex layout with a row horizontal direction, centered along the main axis, and stretched to fill the available height along the cross axis:

     Flex flex = new Flex(Direction.ROW, Justify.CENTER, Align.STRETCH);
     
    See Also:
    Flex(Direction, Justify, Align)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Flex.Align
      Enum representing the possible values for aligning the row's start position on the cross axis.
      static class  Flex.Direction
      Enum representing the possible directions for computing a flex layout.
      static class  Flex.Justify
      Enum representing the possible values for justifying the widget's start position on the cross axis.
    • Field Summary

      • Fields inherited from class ej.mwt.Widget

        NO_CONSTRAINT
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addChild​(ej.mwt.Widget child)  
      protected void computeContentOptimalSize​(ej.mwt.util.Size size)  
      boolean isReverse()
      Checks if the direction is reversed (ROW_REVERSE or COLUMN_REVERSE).
      boolean isRow()
      Checks if the main axis is horizontal (ROW or ROW_REVERSE).
      boolean isStretch()
      Checks if the current align is STRETCH.
      protected void layOutChildren​(int contentWidth, int contentHeight)  
      void removeAllChildren()  
      void removeChild​(ej.mwt.Widget childToRemove)  
      void setAlign​(Flex.Align align)
      Sets the align of the flex.
      void setDirection​(Flex.Direction direction)
      Sets the direction of the flex.
      void setJustify​(Flex.Justify justify)
      Sets the justify of the flex.
      • Methods inherited from class ej.mwt.Container

        changeChildIndex, computeChildOptimalSize, getChild, getChildIndex, getChildren, getChildrenCount, getContentBounds, getContentHeight, getContentWidth, getContentX, getContentY, getWidgetAt, insertChild, layOutAlignedChild, layOutChild, renderChild, renderContent, replaceChild, setHiddenChild, setHiddenChildren, setShownChild, setShownChildren, updateStyle
      • Methods inherited from class ej.mwt.Widget

        addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getDesktop, getHeight, getParent, getStyle, getWidth, getX, getY, handleEvent, hasClassSelector, isAttached, isEnabled, isInState, isShown, isTransparent, onAttached, onDetached, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Flex

        public Flex​(Flex.Direction direction,
                    Flex.Justify justify,
                    Flex.Align alignment)
        Creates a flex container specifying its layout parameters.
        Parameters:
        direction - the main axis direction for the layout (e.g., Direction.ROW or Flex.Direction.COLUMN).
        justify - the alignment of items along the main axis (e.g., Justify.START, Justify.CENTER or Justify.END).
        alignment - the alignment of items along the cross axis (e.g., Align.STRETCH (default), Align.CENTER, Align.END).
    • Method Detail

      • computeContentOptimalSize

        protected void computeContentOptimalSize​(ej.mwt.util.Size size)
        Specified by:
        computeContentOptimalSize in class ej.mwt.Widget
      • layOutChildren

        protected void layOutChildren​(int contentWidth,
                                      int contentHeight)
        Specified by:
        layOutChildren in class ej.mwt.Container
      • setDirection

        public void setDirection​(Flex.Direction direction)
        Sets the direction of the flex.
        Parameters:
        direction - the direction to set.
      • setJustify

        public void setJustify​(Flex.Justify justify)
        Sets the justify of the flex.
        Parameters:
        justify - the justify to set.
      • setAlign

        public void setAlign​(Flex.Align align)
        Sets the align of the flex.
        Parameters:
        align - the align to set.
      • isRow

        public boolean isRow()
        Checks if the main axis is horizontal (ROW or ROW_REVERSE).
        Returns:
        true if the main axis is horizontal, false otherwise.
      • isReverse

        public boolean isReverse()
        Checks if the direction is reversed (ROW_REVERSE or COLUMN_REVERSE).
        Returns:
        true if the direction is reversed, false otherwise.
      • isStretch

        public boolean isStretch()
        Checks if the current align is STRETCH.
        Returns:
        true if align is STRETCH, false otherwise.
      • addChild

        public void addChild​(ej.mwt.Widget child)
        Overrides:
        addChild in class ej.mwt.Container
      • removeChild

        public void removeChild​(ej.mwt.Widget childToRemove)
        Overrides:
        removeChild in class ej.mwt.Container
      • removeAllChildren

        public void removeAllChildren()
        Overrides:
        removeAllChildren in class ej.mwt.Container