Enum Class UniformGridLayout.Mode

java.lang.Object
java.lang.Enum<UniformGridLayout.Mode>
swingtree.layout.UniformGridLayout.Mode
All Implemented Interfaces:
Serializable, Comparable<UniformGridLayout.Mode>, Constable
Enclosing class:
UniformGridLayout

public static enum UniformGridLayout.Mode extends Enum<UniformGridLayout.Mode>
Decides how the grid of a UniformGridLayout is built from the declared number of rows, the declared number of columns and the number of components in the container. In both modes, the grid is filled row by row, and a number of rows or columns of 0 means "as many as the components need". The mode only shapes a grid which still has a cell for every component; once there are more components than the declared numbers multiply to, the UniformGridLayout.OverflowGrowth setting decides the shape instead. The UniformGridLayout.CollapseEmpty setting then decides which of the rows and columns that no component occupies are left out.

This is how each mode builds a grid declared with 2 rows and 5 columns, as rows × columns, before any empty rows or columns are left out:

See Also:
  • Enum Constant Details

    • WRAP_AFTER_COLUMNS

      public static final UniformGridLayout.Mode WRAP_AFTER_COLUMNS
      A new row starts after every declared number of columns, so the grid has the declared number of columns and at least the declared number of rows. When there are more components than cells, the UniformGridLayout.OverflowGrowth setting decides whether the grid grows by rows, by columns or by both. This is the default mode.

      A grid of 2 rows and 5 columns builds 2 rows of 5 columns for 8 components, and, with the default UniformGridLayout.OverflowGrowth.ADD_ROWS, 3 rows of 5 columns for 11 components. While the grid keeps its declared number of columns, the component at index i is always in row i / columns and column i % columns, so adding a component never moves one of the components before it into another row or column.

      If the declared number of columns is 0, the grid gets as many columns as it takes to fit the components into the declared number of rows, and can never overflow.

    • SPREAD_OVER_ROWS

      public static final UniformGridLayout.Mode SPREAD_OVER_ROWS
      The components are spread over the declared number of rows in as many columns as they need, so the declared number of columns does not shape the grid. It still counts the cells: once there are more components than the declared rows times the declared columns, the UniformGridLayout.OverflowGrowth setting decides whether the grid makes room by rows, by columns or by both, exactly as it does in WRAP_AFTER_COLUMNS.

      A grid of 2 rows and 5 columns builds 2 columns for 3 components and 4 columns for 8 components. Its 11th component overflows the declared 10 cells, and from there the growth policy answers: 6 columns under UniformGridLayout.OverflowGrowth.ADD_COLUMNS, a third row under the default UniformGridLayout.OverflowGrowth.ADD_ROWS. A grid of 0 rows builds its declared number of columns, and as many rows as its components need.

      UniformGridLayout.OverflowGrowth.ADD_COLUMNS is the policy which keeps widening the grid the way the GridLayout of the JDK does, so a UniformGridLayout in this mode, with UniformGridLayout.CollapseEmpty.NONE and that growth policy, can replace a GridLayout without changing where any component ends up.

  • Method Details

    • values

      public static UniformGridLayout.Mode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static UniformGridLayout.Mode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null