Skip navigation links
acm.gui

Class TableLayout

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int BOTH
      Resize component in both directions
      static int BOTTOM
      Align table vertically at the bottom of its container
      static int CENTER
      Center table in the container
      static int FILL
      Expand table to fill its container
      static int HORIZONTAL
      Resize component in horizontal direction only
      static int LEFT
      Align table horizontally at the left of its container
      static int NONE
      Do not resize component
      static int RIGHT
      Align table horizontally at the right of its container
      static int TOP
      Align table vertically at the top of its container
      static int VERTICAL
      Resize component in vertical direction only
    • Constructor Summary

      Constructors 
      Constructor and Description
      TableLayout()
      Creates a new TableLayout object with no limits on the number of rows and columns.
      TableLayout(int rows, int columns)
      Creates a new TableLayout object with the specified number of rows and columns.
      TableLayout(int rows, int columns, int hgap, int vgap)
      Creates a new TableLayout object with the specified row count, column count, alignment, horizontal gap, and vertical gap.
    • Field Detail

      • HORIZONTAL

        public static final int HORIZONTAL
        Resize component in horizontal direction only
        See Also:
        Constant Field Values
      • VERTICAL

        public static final int VERTICAL
        Resize component in vertical direction only
        See Also:
        Constant Field Values
      • LEFT

        public static final int LEFT
        Align table horizontally at the left of its container
        See Also:
        Constant Field Values
      • RIGHT

        public static final int RIGHT
        Align table horizontally at the right of its container
        See Also:
        Constant Field Values
      • TOP

        public static final int TOP
        Align table vertically at the top of its container
        See Also:
        Constant Field Values
      • BOTTOM

        public static final int BOTTOM
        Align table vertically at the bottom of its container
        See Also:
        Constant Field Values
    • Constructor Detail

      • TableLayout

        public TableLayout()
        Creates a new TableLayout object with no limits on the number of rows and columns.
        Usage:
        TableLayout layout = new TableLayout();
      • TableLayout

        public TableLayout(int rows,
                           int columns)
        Creates a new TableLayout object with the specified number of rows and columns.
        Parameters:
        rows - The number of rows, or 0 for no limit
        columns - The number of columns, or 0 for no limit
        Usage:
        TableLayout layout = new TableLayout(rows, columns);
      • TableLayout

        public TableLayout(int rows,
                           int columns,
                           int hgap,
                           int vgap)
        Creates a new TableLayout object with the specified row count, column count, alignment, horizontal gap, and vertical gap.
        Parameters:
        rows - The number of rows, or 0 for no limit
        columns - The number of columns, or 0 for no limit
        hgap - The horizontal gap between columns
        vgap - The vertical gap between rows
        Usage:
        TableLayout layout = new TableLayout(rows, columns, hgap, vgap);
    • Method Detail

      • setColumnCount

        public void setColumnCount(int columns)
        Resets the number of columns in the table.
        Parameters:
        columns - The new number of columns
        Usage:
        layout.setColumnCount(columns);
      • getColumnCount

        public int getColumnCount()
        Returns the number of columns in the table.
        Returns:
        The number of columns
        Usage:
        int columns = layout.getColumnCount();
      • setRowCount

        public void setRowCount(int rows)
        Resets the number of rows in the table.
        Parameters:
        rows - The new number of rows
        Usage:
        layout.setRowCount(rows);
      • getRowCount

        public int getRowCount()
        Returns the number of rows in the table.
        Returns:
        The number of rows
        Usage:
        int rows = layout.getRowCount();
      • setHorizontalAlignment

        public void setHorizontalAlignment(int align)
        Sets the horizontal alignment for the table. The legal values are CENTER, LEFT, RIGHT, and FILL.
        Parameters:
        align - The horizontal alignment for the table
        Usage:
        layout.setHorizontalAlignment(align);
      • getHorizontalAlignment

        public int getHorizontalAlignment()
        Returns the horizontal alignment for the table.
        Returns:
        The horizontal alignment for the table
        Usage:
        int align = layout.getHorizontalAlignment();
      • setVerticalAlignment

        public void setVerticalAlignment(int align)
        Sets the vertical alignment for the table. The legal values are CENTER, TOP, BOTTOM, and FILL.
        Parameters:
        align - The vertical alignment for the table
        Usage:
        layout.setVerticalAlignment(align);
      • getVerticalAlignment

        public int getVerticalAlignment()
        Returns the vertical alignment for the table.
        Returns:
        The vertical alignment for the table
        Usage:
        int align = layout.getVerticalAlignment();
      • setDefaultFill

        public void setDefaultFill(int fill)
        Sets the default fill parameter for components in the table. The legal values are NONE, HORIZONTAL, VERTICAL, and BOTH.
        Parameters:
        fill - The default fill parameter for components in the table
        Usage:
        layout.setDefaultFill(fill);
      • getDefaultFill

        public int getDefaultFill()
        Returns the default fill parameter for components in the table.
        Returns:
        The default fill parameter for components in the table
        Usage:
        int fill = layout.getDefaultFill();
      • setHgap

        public void setHgap(int pixels)
        Sets the horizontal gap between components.
        Parameters:
        pixels - The gap between components in pixels
        Usage:
        layout.setHgap(pixels);
      • getHgap

        public int getHgap()
        Returns the horizontal gap between components.
        Returns:
        The horizontal gap between components
        Usage:
        int hgap = layout.getHgap();
      • setVgap

        public void setVgap(int pixels)
        Sets the vertical gap between components.
        Parameters:
        pixels - The gap between components in pixels
        Usage:
        layout.setVgap(pixels);
      • getVgap

        public int getVgap()
        Returns the vertical gap between components.
        Returns:
        The vertical gap between components
        Usage:
        int vgap = layout.getVgap();
      • setStrictGridBagModel

        public void setStrictGridBagModel(boolean flag)
        Sets a flag indicating whether the layout manager should match the model used in GridBagLayout even when that interpretation seems wrong. The differences show up in the following areas:
        • Calculation of cell size. GridBagLayout uses the minimum layout size of the component to determine the size of each cell; TableLayout uses the preferred size. In practice, these two values are often the same, but it seems that the preferred size makes considerably more sense in terms of how this layout is used.
        • Treatment of cells spanning several rows. In GridBagLayout, each new row begins after the last multirow cell in that row, even if there is space to its left. By default, TableLayout uses the HTML model in which the cells begin at the left margin unless that column is itself already occupied.
        Parameters:
        flag - true to use a strict GridBagLayout model
        Usage:
        layout.setStrictGridBagModel(flag);
        Noshow:
      • isStrictGridBagModel

        public boolean isStrictGridBagModel()
        Returns true if this layout manager is treating multirow cells exactly as GridBagLayout does.
        Returns:
        true if this manager is using the strict GridBagLayout model
        Usage:
        if (layout.isStrictGridBagModel()) . . .
        Noshow:
      • setConstraints

        public void setConstraints(Component comp,
                                   GridBagConstraints constraints)
        Sets the constraints for the component to a copy of the supplied constraints.
        Parameters:
        comp - The component to be constrained
        constraints - The constraints object used to specify the layout
        Usage:
        layout.setConstraints(comp, constraints);
      • setConstraints

        public void setConstraints(Component comp,
                                   String constraints)
        Sets the constraints for the component to the constraints specified by the string.
        Parameters:
        comp - The component to be constrained
        constraints - A string specifying the constraints
        Usage:
        layout.setConstraints(comp, constraints);
      • getConstraints

        public acm.gui.TableConstraints getConstraints(Component comp)
        Returns a copy of the constraints requested for the specified component. The constraints value is always converted to a TableConstraints so that clients can use this class in preference to GridBagConstraints without needing a type cast.
        Parameters:
        comp - The component whose constraints are requested
        Returns:
        A copy of the constraints object used to specify the layout
        Usage:
        TableConstraints tc = layout.getConstraints(comp);
      • addLayoutComponent

        public void addLayoutComponent(String constraints,
                                       Component comp)
        Adds a component to the layout. Implements LayoutManager.
        Specified by:
        addLayoutComponent in interface LayoutManager
        Parameters:
        constraints - The constraint string
        comp - The component to be added
        Noshow:
      • 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
        Noshow:
      • preferredLayoutSize

        public Dimension preferredLayoutSize(Container target)
        Calculates the preferred size for the FrameLayout component when laid out in the target container.
        Specified by:
        preferredLayoutSize in interface LayoutManager
        Parameters:
        target - The container in which the layout is done
        Returns:
        The preferred dimensions for the layout
        Noshow:
      • minimumLayoutSize

        public Dimension minimumLayoutSize(Container target)
        Calculates the minimum size for the FrameLayout component when laid out in the target container.
        Specified by:
        minimumLayoutSize in interface LayoutManager
        Parameters:
        target - The container in which the layout is done
        Returns:
        The minimum dimensions for the layout
        Noshow:
      • layoutContainer

        public void layoutContainer(Container target)
        Lays out the components in the target container.
        Specified by:
        layoutContainer in interface LayoutManager
        Parameters:
        target - The container in which the layout is done
        Noshow:
      • addLayoutComponent

        public void addLayoutComponent(Component comp,
                                       Object constraints)
        Adds a component to the layout. The TableLayout class overrides this method to allow for string constraints.
        Specified by:
        addLayoutComponent in interface LayoutManager2
        Parameters:
        comp - The component to be added
        constraints - The constraint object
        Noshow:
      • maximumLayoutSize

        public Dimension maximumLayoutSize(Container target)
        Calculates the maximum size for the FrameLayout component when laid out in the target container.
        Specified by:
        maximumLayoutSize in interface LayoutManager2
        Parameters:
        target - The container in which the layout is done
        Returns:
        The maximum dimensions for the layout
        Noshow:
      • getLayoutAlignmentX

        public float getLayoutAlignmentX(Container target)
        Returns the alignment along the x-axis as described in the LayoutManager2 interface.
        Specified by:
        getLayoutAlignmentX in interface LayoutManager2
        Parameters:
        target - The container in which the layout is done
        Returns:
        A value between 0 and 1 indicating where this component should align
        Noshow:
      • getLayoutAlignmentY

        public float getLayoutAlignmentY(Container target)
        Returns the alignment along the y-axis as described in the LayoutManager2 interface.
        Specified by:
        getLayoutAlignmentY in interface LayoutManager2
        Parameters:
        target - The container in which the layout is done
        Returns:
        A value between 0 and 1 indicating where this component should align
        Noshow:
      • invalidateLayout

        public void invalidateLayout(Container target)
        Indicates that the layout is no longer valid.
        Specified by:
        invalidateLayout in interface LayoutManager2
        Parameters:
        target - The container in which the layout is done
        Noshow:
      • toString

        public String toString()
        Creates a printable representation of the layout.
        Overrides:
        toString in class Object
        Noshow:
      • lookupConstraints

        protected GridBagConstraints lookupConstraints(Component comp)
        Returns the constraints object for the specified component.
        Parameters:
        comp - The component to be constrained
        Returns:
        The constraints object used to specify the layout
        Usage:
        GridBagConstraints gbc = layout.lookupConstraints(comp);
      • lookupConstraints

        protected acm.gui.TableConstraints lookupConstraints(Component comp,
                                                             Container target)
        Returns the TableConstraints object actually applied to the specified component when it is laid out in the target container. In the result of this method the values of the gridx, gridx, gridwidth, and gridheight fields are filled in according to the actual position in the grid.
        Parameters:
        comp - The component to be constrained
        target - The container in which the layout is done
        Returns:
        The constraints object actually applied to the layout
        Usage:
        TableConstraints tc = layout.lookupConstraints(comp, target);