Class ENHGridLayout

  • All Implemented Interfaces:
    java.awt.LayoutManager, java.io.Serializable
    Direct Known Subclasses:
    AlignLayout

    public class ENHGridLayout
    extends java.awt.GridLayout
    ENHGridLayout is an improved subclass of GridLayout. It lays out a grid of rows and columns based on the attributes of the individual rows and columns. ENHGridLayout uses the widest element in a column to set the width of that column, and the tallest element in a row to set the height of that row.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int[] col_widths
      Array of column widths.
      protected int cols
      The number of columns in the layout, as set by the user.
      protected int hgap
      The horiztonal gap between items.
      protected int[] row_heights
      Array of row heights.
      protected int rows
      The number of rows in the layout, as set by the user.
      static int VARIABLE  
      protected int vgap
      The vertical gap between items.
    • Constructor Summary

      Constructors 
      Constructor Description
      ENHGridLayout​(int rows, int cols)
      Creates a grid layout with the specified number of rows and columns.
      ENHGridLayout​(int rows, int cols, int hgap, int vgap)
      Creates a grid layout with the specified rows, columns, horizontal gap, and vertical gap.
    • Method Summary

      Modifier and Type Method Description
      protected void getGridSizes​(java.awt.Container parent, boolean min)
      Traverses the children and determines row heights and column widths.
      void layoutContainer​(java.awt.Container parent)
      Performs the layout of the children.
      java.awt.Dimension minimumLayoutSize​(java.awt.Container parent)
      Returns the minimum dimensions needed to layout the components contained in the specified panel.
      java.awt.Dimension preferredLayoutSize​(java.awt.Container parent)
      Calculates the preferred size for this layout.
      protected void setBounds​(int pos, int row, int col, java.awt.Component comp, int x, int y, int w, int h)  
      • Methods inherited from class java.awt.GridLayout

        addLayoutComponent, getColumns, getHgap, getRows, getVgap, removeLayoutComponent, setColumns, setHgap, setRows, setVgap, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • hgap

        protected int hgap
        The horiztonal gap between items.
      • vgap

        protected int vgap
        The vertical gap between items.
      • rows

        protected int rows
        The number of rows in the layout, as set by the user. This number may not correspond exactly to the number of rows in the layout.
      • cols

        protected int cols
        The number of columns in the layout, as set by the user. This number may not correspond exactly to the number of columns in the layout.
      • row_heights

        protected int[] row_heights
        Array of row heights. It is accurate only after a call to getGridSizes()
      • col_widths

        protected int[] col_widths
        Array of column widths. It is accurate only after a call to getGridSizes()
    • Constructor Detail

      • ENHGridLayout

        public ENHGridLayout​(int rows,
                             int cols)
        Creates a grid layout with the specified number of rows and columns.
        Parameters:
        rows - the number of rows in the layout
        cols - the number of columns in the layout
      • ENHGridLayout

        public ENHGridLayout​(int rows,
                             int cols,
                             int hgap,
                             int vgap)
        Creates a grid layout with the specified rows, columns, horizontal gap, and vertical gap.
        Parameters:
        rows - the rows; VARIABLE (0) means 'any number.'
        cols - the columns; VARIABLE (0) means 'any number.' Only one of 'rows' and 'cols' can be VARIABLE, not both.
        hgap - the horizontal gap variable
        vgap - the vertical gap variable
        Throws:
        java.lang.IllegalArgumentException - If the rows and columns are invalid.
    • Method Detail

      • getGridSizes

        protected void getGridSizes​(java.awt.Container parent,
                                    boolean min)
        Traverses the children and determines row heights and column widths.
        Parameters:
        parent - the component which needs to be laid out
        min - if true, the minimum size is used. Otherwise, the preferred size is used.
      • preferredLayoutSize

        public java.awt.Dimension preferredLayoutSize​(java.awt.Container parent)
        Calculates the preferred size for this layout.
        Specified by:
        preferredLayoutSize in interface java.awt.LayoutManager
        Overrides:
        preferredLayoutSize in class java.awt.GridLayout
        Parameters:
        parent - the component which needs to be laid out
      • minimumLayoutSize

        public java.awt.Dimension minimumLayoutSize​(java.awt.Container parent)
        Returns the minimum dimensions needed to layout the components contained in the specified panel.
        Specified by:
        minimumLayoutSize in interface java.awt.LayoutManager
        Overrides:
        minimumLayoutSize in class java.awt.GridLayout
        Parameters:
        parent - the component which needs to be laid out
      • setBounds

        protected void setBounds​(int pos,
                                 int row,
                                 int col,
                                 java.awt.Component comp,
                                 int x,
                                 int y,
                                 int w,
                                 int h)
      • layoutContainer

        public void layoutContainer​(java.awt.Container parent)
        Performs the layout of the children. It calculates the number of actual rows and columns based on the user's settings, retrieves row height and column width information, then moves all the children to the appropriate places.
        Specified by:
        layoutContainer in interface java.awt.LayoutManager
        Overrides:
        layoutContainer in class java.awt.GridLayout
        Parameters:
        parent - the specified component being laid out