ProgramixGenericLib v5.0.1

com.programix.gui.layout
Class StackLayout

java.lang.Object
  extended by com.programix.gui.layout.AbstractTableLayout
      extended by com.programix.gui.layout.AnchorTableLayout
          extended by com.programix.gui.layout.StackLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class StackLayout
extends AnchorTableLayout

Lays out components in a vertical stack (single column). Each component added gets its preferred height. The row gap specifies how many pixels are between each row in the stack (the inherited column gap has no effect on this layout as there is always only one column). The border gap specifies the distance between the laid out components and the container's own border (if any).

The AnchorPoint specified for the layout manager indicates where the contents of the container should be placed if there is extra room. See AbstractTableLayout.getAnchorPoint(), AbstractTableLayout.setAnchorPoint(com.programix.gui.AnchorPoint), and the AnchorPoint that may be specified during construction.

When components are added to this container, an optional constraint can be specified for each. If no constraint is specified (or if null is used as the constraint), the default of AnchorPoint.CENTER will be used.


Example: StackLayoutBasic
Could have been created from:
 public static JPanel createBasicDemoPane() {
     JPanel basicStack = new JPanel(new StackLayout());
     basicStack.setBorder(
         BorderFactory.createMatteBorder(10, 10, 10, 10, Color.BLUE));
     basicStack.add(makeLabel("apple", Color.RED));
     basicStack.add(makeLabel("banana", Color.YELLOW));
     basicStack.add(makeLabel("cherry", Color.GREEN));
     basicStack.add(makeLabel("grapefruit", Color.MAGENTA));
     basicStack.add(makeLabel("pear", Color.ORANGE));
     basicStack.add(makeLabel("watermelon", Color.CYAN));
     return basicStack;
 }
 
 public static JLabel makeLabel(String text, Color bgColor) {
     JLabel label = new JLabel(text, JLabel.CENTER);
     label.setOpaque(true);
     label.setBackground(bgColor);
     label.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
     return label;
 }
 

Example: StackLayoutAnchor
Could have been created from:
 StackLayout stackLayout = new StackLayout(AnchorPoint.TOP_FLEX_WIDTH);
 JPanel anotherStack = new JPanel(stackLayout);
 anotherStack.setBorder(
     BorderFactory.createMatteBorder(10, 10, 10, 10, Color.BLUE));
 anotherStack.add(
     makeLabel("apple", Color.RED), AnchorPoint.WEST);
 anotherStack.add(
     makeLabel("banana", Color.YELLOW), AnchorPoint.CENTER);
 anotherStack.add(
     makeLabel("cherry", Color.GREEN), AnchorPoint.EAST);
 anotherStack.add(makeLabel("grapefruit", Color.MAGENTA));
 anotherStack.add(
     makeLabel("pear", Color.ORANGE), AnchorPoint.CENTER_FLEX_WIDTH);
 anotherStack.add(makeLabel("watermelon", Color.CYAN));
 

Example: StackLayoutColumnAnchor
Could have been created from:
 StackLayout stackLayout = new StackLayout(AnchorPoint.TOP_FLEX_WIDTH);
 stackLayout.setColumnAnchorPoint(0, AnchorPoint.WEST);
 JPanel anotherStack = new JPanel(stackLayout);
 anotherStack.setBorder(
     BorderFactory.createMatteBorder(10, 10, 10, 10, Color.BLUE));
 anotherStack.add(
     makeLabel("apple", Color.RED), AnchorPoint.WEST);
 anotherStack.add(
     makeLabel("banana", Color.YELLOW), AnchorPoint.CENTER);
 anotherStack.add(
     makeLabel("cherry", Color.GREEN), AnchorPoint.EAST);
 anotherStack.add(makeLabel("grapefruit", Color.MAGENTA));
 anotherStack.add(
     makeLabel("pear", Color.ORANGE), AnchorPoint.CENTER_FLEX_WIDTH);
 anotherStack.add(makeLabel("watermelon", Color.CYAN));
 

Author:
Paul Hyde
See Also:
AnchorTableLayout, FormLayout, ColumnButtonLayout, RowButtonLayout, ShelfLayout, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.programix.gui.layout.AnchorTableLayout
AnchorTableLayout.AnchorTableCellData
 
Nested classes/interfaces inherited from class com.programix.gui.layout.AbstractTableLayout
AbstractTableLayout.CellData
 
Field Summary
 
Fields inherited from class com.programix.gui.layout.AbstractTableLayout
anchorPoint, borderGap, colGap, columnCoordinator, DEFAULT_ANCHOR_POINT, DEFAULT_BORDER_GAP, DEFAULT_COL_GAP, DEFAULT_ROW_GAP, ignoreInvisibleComponents, rowGap
 
Constructor Summary
StackLayout()
          Creates a single column (stack) layout.
StackLayout(AnchorPoint anchorPoint)
          Creates a single column (stack) layout.
StackLayout(int borderGap)
          Creates a single column (stack) layout.
StackLayout(int rowGap, int borderGap)
          Creates a single column (stack) layout.
StackLayout(int rowGap, int borderGap, AnchorPoint anchorPoint)
          Creates a single column (stack) layout.
 
Method Summary
 void setColumnCount(int columnCount)
          It is meaningless to set this to anything other than 1 as this layout manager always has exactly one column.
 
Methods inherited from class com.programix.gui.layout.AnchorTableLayout
addLayoutComponent, createCellData, getColumnAnchorPoint, getColumnCount, getColumnHeaderAnchorPoint, getLayoutAlignmentX, getLayoutAlignmentY, invalidateLayout, maximumLayoutSize, removeLayoutComponent, setColumnAnchorPoint, setColumnHeaderAnchorPoint
 
Methods inherited from class com.programix.gui.layout.AbstractTableLayout
addLayoutComponent, getAnchorPoint, getBorderGap, getColumnCoordinator, getColumnGap, getRowGap, isIgnoreInvisibleComponents, layoutContainer, minimumLayoutSize, preferredLayoutSize, setAnchorPoint, setBorderGap, setColumnCoordinator, setColumnGap, setIgnoreInvisibleComponents, setRowGap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.LayoutManager
addLayoutComponent, layoutContainer, minimumLayoutSize, preferredLayoutSize
 

Constructor Detail

StackLayout

public StackLayout(int rowGap,
                   int borderGap,
                   AnchorPoint anchorPoint)
Creates a single column (stack) layout.

Parameters:
rowGap - space between rows. See setRowGap().
borderGap - space around the outside of the column. See setBorderGap().
anchorPoint - region to anchor to when there is extra space See setAnchorPoint().

StackLayout

public StackLayout(int rowGap,
                   int borderGap)
Creates a single column (stack) layout. Uses DEFAULT_ANCHOR_POINT.

Parameters:
rowGap - space between rows. See setRowGap().
borderGap - space around the outside of the form. See setBorderGap().

StackLayout

public StackLayout(AnchorPoint anchorPoint)
Creates a single column (stack) layout. Uses DEFAULT_ROW_GAP. Uses DEFAULT_BORDER_GAP.

Parameters:
anchorPoint - region to anchor to when there is extra space See setAnchorPoint().

StackLayout

public StackLayout(int borderGap)
Creates a single column (stack) layout. Uses DEFAULT_ROW_GAP. Uses DEFAULT_ANCHOR_POINT.

Parameters:
borderGap - space around the outside of the form. See setBorderGap().

StackLayout

public StackLayout()
Creates a single column (stack) layout. Uses DEFAULT_ROW_GAP. Uses DEFAULT_BORDER_GAP. Uses DEFAULT_ANCHOR_POINT.

Method Detail

setColumnCount

public final void setColumnCount(int columnCount)
It is meaningless to set this to anything other than 1 as this layout manager always has exactly one column. This overriding version ignores the parameter passed in and always passes 1 to the superclass' implementation. There is no exception or warning if a value other that 1 is passed; it is just ignored.

Overrides:
setColumnCount in class AnchorTableLayout
Parameters:
columnCount - new number of columns; must be at least one. If this is the same as the current number of columns, this method call does nothing.

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.