Class TableLayout

java.lang.Object
com.bc.ceres.swing.TableLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2

public class TableLayout extends Object implements LayoutManager2
A convenient layout manager that allows multiple components to be laid out in form of a table-like grid.

It uses the same parameters as Swing's standard GridBagLayout manager, however clients don't have to deal with GridBagConstraints. Instead, they can easily use the the various setters to adjust single parameters. Parameters can be specified for

  1. the entire table: setTable<Param>(),
  2. an entire row: setRow<Param>(),
  3. an entire column: setColumn<Param>(),
  4. each cell separately: setCell<Param>().
Note that type-safe enums exists for the fill and anchor parameter values.

Any parameter settings may be removed from the layout by passing null as value.

Components are added to their container using a cell(row, col) or cell(row, col, rowspan, colspan) constraint, for example:

      panel.add(new JLabel("Iterations:"), TableLayout.cell(0, 3));
 
  • Constructor Details

    • TableLayout

      public TableLayout()
    • TableLayout

      public TableLayout(int columnCount)
  • Method Details

    • getColumnCount

      public int getColumnCount()
    • setColumnCount

      public void setColumnCount(int columnCount)
    • setCellColspan

      public void setCellColspan(int row, int col, Integer colspan)
    • setCellRowspan

      public void setCellRowspan(int row, int col, Integer rowspan)
    • setTablePadding

      public void setTablePadding(int hpadding, int vpadding)
    • setTablePadding

      public void setTablePadding(Insets insets)
    • setRowPadding

      public void setRowPadding(int row, Insets insets)
    • setColumnPadding

      public void setColumnPadding(int col, Insets insets)
    • setCellPadding

      public void setCellPadding(int row, int col, Insets insets)
    • setTableWeightX

      public void setTableWeightX(Double weightx)
    • setRowWeightX

      public void setRowWeightX(int row, Double weightx)
    • setColumnWeightX

      public void setColumnWeightX(int col, Double weightx)
    • setCellWeightX

      public void setCellWeightX(int row, int col, Double weightx)
    • setTableWeightY

      public void setTableWeightY(Double weighty)
    • setRowWeightY

      public void setRowWeightY(int row, Double weighty)
    • setColumnWeightY

      public void setColumnWeightY(int col, Double weighty)
    • setCellWeightY

      public void setCellWeightY(int row, int col, Double weighty)
    • setTableFill

      public void setTableFill(TableLayout.Fill fill)
    • setRowFill

      public void setRowFill(int row, TableLayout.Fill fill)
    • setColumnFill

      public void setColumnFill(int col, TableLayout.Fill fill)
    • setCellFill

      public void setCellFill(int row, int col, TableLayout.Fill fill)
    • setTableAnchor

      public void setTableAnchor(TableLayout.Anchor anchor)
    • setRowAnchor

      public void setRowAnchor(int row, TableLayout.Anchor anchor)
    • setColumnAnchor

      public void setColumnAnchor(int col, TableLayout.Anchor anchor)
    • setCellAnchor

      public void setCellAnchor(int row, int col, TableLayout.Anchor anchor)
    • createHorizontalSpacer

      public Component createHorizontalSpacer()
    • createVerticalSpacer

      public Component createVerticalSpacer()
    • getLayoutAlignmentX

      public float getLayoutAlignmentX(Container target)
      Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
      Specified by:
      getLayoutAlignmentX in interface LayoutManager2
    • getLayoutAlignmentY

      public float getLayoutAlignmentY(Container target)
      Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
      Specified by:
      getLayoutAlignmentY in interface LayoutManager2
    • invalidateLayout

      public void invalidateLayout(Container target)
      Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
      Specified by:
      invalidateLayout in interface LayoutManager2
    • addLayoutComponent

      public void addLayoutComponent(Component comp, Object constraints)
      Adds the specified component to the layout, using the specified constraint object.
      Specified by:
      addLayoutComponent in interface LayoutManager2
      Parameters:
      comp - the component to be added
      constraints - where/how the component is added to the layout.
    • addLayoutComponent

      public void addLayoutComponent(String name, Component comp)
      Has no effect, since this layout manager does not use a per-component string.
      Specified by:
      addLayoutComponent in interface LayoutManager
    • removeLayoutComponent

      public void removeLayoutComponent(Component comp)
      Removes the specified component from the layout.
      Specified by:
      removeLayoutComponent in interface LayoutManager
      Parameters:
      comp - the component to be removed
    • layoutContainer

      public void layoutContainer(Container parent)
      Lays out the specified container.
      Specified by:
      layoutContainer in interface LayoutManager
      Parameters:
      parent - the container to be laid out
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container parent)
      Calculates the minimum size dimensions for the specified container, given the components it contains.
      Specified by:
      minimumLayoutSize in interface LayoutManager
      Parameters:
      parent - the component to be laid out
      See Also:
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Calculates the preferred size dimensions for the specified container, given the components it contains.
      Specified by:
      preferredLayoutSize in interface LayoutManager
      Parameters:
      parent - the container to be laid out
      See Also:
    • maximumLayoutSize

      public Dimension maximumLayoutSize(Container parent)
      Calculates the maximum size dimensions for the specified container, given the components it contains.
      Specified by:
      maximumLayoutSize in interface LayoutManager2
      See Also:
    • cell

      public static TableLayout.Cell cell()
    • cell

      public static TableLayout.Cell cell(int row, int col)
    • cell

      public static TableLayout.Cell cell(int row, int col, int rowspan, int colspan)
    • toString

      public String toString()
      Overrides:
      toString in class Object