Class StackLayout

  • All Implemented Interfaces:
    java.awt.LayoutManager, java.awt.LayoutManager2

    public class StackLayout
    extends java.lang.Object
    implements java.awt.LayoutManager2

    StackLayout is a Swing layout aimed to act as the layers stack of most popuplar graphics editing tools like The GIMP or Photoshop. While similar to CardLayout, this layout displays all the components of the container. If you are using non-rectangular components (i.e. transparent) you will see them from top to bottom of the stack.

    When using this layout, each component can be added in the container either on top of the stack or at the bootom:

     JPanel panel = new JPanel(new StackLayout());
     panel.add(new JLabel("On top"),    StackLayout.TOP);
     panel.add(new JLabel("At bottom"), StackLayout.BOTTOM);
     
    If you don't specify the constraint, the component will be added at the top of the components stack.

    All the components managed by this layout will be given the same size as the container itself. The minimum, maximum and preferred size of the container are based upon the largest minimum, maximum and preferred size of the children components.

    StackLayout works only with JSE 1.5 and Java SE 6 and greater.

    Author:
    Romain Guy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BOTTOM
      Use this constraint to add a component at the bottom of the stack.
      static java.lang.String TOP
      Use this contrainst to add a component at the top of the stack.
    • Constructor Summary

      Constructors 
      Constructor Description
      StackLayout()  
    • Field Detail

      • BOTTOM

        public static final java.lang.String BOTTOM
        Use this constraint to add a component at the bottom of the stack.
        See Also:
        Constant Field Values
      • TOP

        public static final java.lang.String TOP
        Use this contrainst to add a component at the top of the stack.
        See Also:
        Constant Field Values
    • Constructor Detail

      • StackLayout

        public StackLayout()
    • Method Detail

      • addLayoutComponent

        public void addLayoutComponent​(java.awt.Component comp,
                                       java.lang.Object constraints)
        Specified by:
        addLayoutComponent in interface java.awt.LayoutManager2
      • addLayoutComponent

        public void addLayoutComponent​(java.lang.String name,
                                       java.awt.Component comp)
        Specified by:
        addLayoutComponent in interface java.awt.LayoutManager
      • removeLayoutComponent

        public void removeLayoutComponent​(java.awt.Component comp)
        Specified by:
        removeLayoutComponent in interface java.awt.LayoutManager
      • getLayoutAlignmentX

        public float getLayoutAlignmentX​(java.awt.Container target)
        Specified by:
        getLayoutAlignmentX in interface java.awt.LayoutManager2
      • getLayoutAlignmentY

        public float getLayoutAlignmentY​(java.awt.Container target)
        Specified by:
        getLayoutAlignmentY in interface java.awt.LayoutManager2
      • invalidateLayout

        public void invalidateLayout​(java.awt.Container target)
        Specified by:
        invalidateLayout in interface java.awt.LayoutManager2
      • preferredLayoutSize

        public java.awt.Dimension preferredLayoutSize​(java.awt.Container parent)
        Specified by:
        preferredLayoutSize in interface java.awt.LayoutManager
      • minimumLayoutSize

        public java.awt.Dimension minimumLayoutSize​(java.awt.Container parent)
        Specified by:
        minimumLayoutSize in interface java.awt.LayoutManager
      • maximumLayoutSize

        public java.awt.Dimension maximumLayoutSize​(java.awt.Container target)
        Specified by:
        maximumLayoutSize in interface java.awt.LayoutManager2
      • layoutContainer

        public void layoutContainer​(java.awt.Container parent)
        Specified by:
        layoutContainer in interface java.awt.LayoutManager