| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jdesktop.layout.GroupLayout
public class GroupLayout
GroupLayout is a LayoutManager that hierarchically groups components to achieve common, and not so common, layouts. Grouping is done by instances of the Group class. GroupLayout supports two types of groups:
| Sequential: | A sequential group positions its child elements sequentially, one after another. | 
| Parallel: | A parallel group positions its child elements in the same space on top of each other. Parallel groups can also align the child elements along their baseline. | 
The following code builds a simple layout consisting of two labels in one column, followed by two textfields in the next column:
   JComponent panel = ...;
   GroupLayout layout = new GroupLayout(panel);
   panel.setLayout(layout);
   layout.setAutocreateGaps(true);
   layout.setAutocreateContainerGaps(true);
   GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
   hGroup.add(layout.createParallelGroup().add(label1).add(label2)).
          add(layout.createParallelGroup().add(tf1).add(tf2));
   layout.setHorizontalGroup(hGroup);
   GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
   vGroup.add(layout.createParallelGroup(GroupLayout.BASELINE).add(label1).add(tf1)).
          add(layout.createParallelGroup(GroupLayout.BASELINE).add(label2).add(tf2));
   layout.setVerticalGroup(vGroup);
 
 This layout consists of the following:
add methods.
   add methods of Groups return
       themselves.  This allows for easy chaining of invocations.  For
       example, group.add(label1).add(label2); is equivalent to
       group.add(label1);group.add(label2);.
   GroupLayout.
 setAutocreateGaps() method.  Similarly you can use
 the setAutocreateContainerGaps() method to insert gaps
 between the components and the container.
| Nested Class Summary | |
|---|---|
|  class | GroupLayout.GroupGroup provides for commonality between the two types of operations supported by GroupLayout: laying out components one
 after another (SequentialGroup) or layout on top
 of each other (ParallelGroup). | 
|  class | GroupLayout.ParallelGroupA Groupthat lays out its elements on top of each
 other. | 
|  class | GroupLayout.SequentialGroupA Groupthat lays out its elements sequentially, one
 after another. | 
| Field Summary | |
|---|---|
| static int | BASELINEPossible alignment type. | 
| static int | CENTERPossible alignment type. | 
| static int | DEFAULT_SIZEPossible value for the add methods that takes a Component. | 
| static int | HORIZONTALPossible argument when linking sizes of components. | 
| static int | LEADINGPossible alignment type. | 
| static int | PREFERRED_SIZEPossible value for the add methods that takes a Component. | 
| static int | TRAILINGPossible alignment type. | 
| static int | VERTICALPossible argument when linking sizes of components. | 
| Constructor Summary | |
|---|---|
| GroupLayout(java.awt.Container host)Creates a GroupLayout for the specified JComponent. | |
| Method Summary | |
|---|---|
|  void | addLayoutComponent(java.awt.Component component,
                   java.lang.Object constraints)Notification that a Componenthas been added to
 the parent container. | 
|  void | addLayoutComponent(java.lang.String name,
                   java.awt.Component component)Notification that a Componenthas been added to
 the parent container. | 
|  GroupLayout.ParallelGroup | createBaselineGroup(boolean resizable,
                    boolean anchorBaselineToTop)Creates and returns a ParallelGroupthat aligns it's
 elements along the baseline. | 
|  GroupLayout.ParallelGroup | createParallelGroup()Creates and returns a ParallelGroupwith aLEADINGalignment. | 
|  GroupLayout.ParallelGroup | createParallelGroup(int alignment)Creates and returns an ParallelGroup. | 
|  GroupLayout.ParallelGroup | createParallelGroup(int alignment,
                    boolean resizable)Creates and returns an ParallelGroup. | 
|  GroupLayout.SequentialGroup | createSequentialGroup()Creates and returns a SequentialGroup. | 
|  boolean | getAutocreateContainerGaps()Returns whether or not gaps between the container and the first/last components should automatically be created. | 
|  boolean | getAutocreateGaps()Returns true if gaps between components are automatically be created. | 
|  boolean | getHonorsVisibility()Returns whether component visiblity is considered when sizing and positioning components. | 
|  GroupLayout.Group | getHorizontalGroup()Returns the Groupthat is responsible for
 layout along the horizontal axis. | 
|  float | getLayoutAlignmentX(java.awt.Container parent)Returns the alignment along the x axis. | 
|  float | getLayoutAlignmentY(java.awt.Container parent)Returns the alignment along the y axis. | 
|  LayoutStyle | getLayoutStyle()Returns the LayoutStyle instance to use | 
|  GroupLayout.Group | getVerticalGroup()Returns the ParallelGroupthat is responsible for
 layout along the vertical axis. | 
|  void | invalidateLayout(java.awt.Container parent)Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. | 
|  void | layoutContainer(java.awt.Container parent)Lays out the specified container. | 
|  void | linkSize(java.awt.Component[] components)Forces the set of components to have the same size. | 
|  void | linkSize(java.awt.Component[] components,
         int axis)Forces the set of components to have the same size. | 
|  java.awt.Dimension | maximumLayoutSize(java.awt.Container parent)Returns the maximum size for the specified container. | 
|  java.awt.Dimension | minimumLayoutSize(java.awt.Container parent)Returns the minimum size for the specified container. | 
|  java.awt.Dimension | preferredLayoutSize(java.awt.Container parent)Returns the preferred size for the specified container. | 
|  void | removeLayoutComponent(java.awt.Component component)Notification that a Componenthas been removed from
 the parent container. | 
|  void | replace(java.awt.Component existingComponent,
        java.awt.Component newComponent)Removes an existing component replacing it with the specified component. | 
|  void | setAutocreateContainerGaps(boolean autocreatePadding)Sets whether or not gaps between the container and the first/last components should automatically be created. | 
|  void | setAutocreateGaps(boolean autocreatePadding)Sets whether or not a gap between components should automatically be created. | 
|  void | setHonorsVisibility(boolean honorsVisibility)Sets whether component visiblity is considered when sizing and positioning components. | 
|  void | setHonorsVisibility(java.awt.Component component,
                    java.lang.Boolean honorsVisibility)Sets whether the component's visiblity is considered for sizing and positioning. | 
|  void | setHorizontalGroup(GroupLayout.Group group)Sets the Groupthat is responsible for
 layout along the horizontal axis. | 
|  void | setLayoutStyle(LayoutStyle layoutStyle)Sets the LayoutStyle this GroupLayout is to use. | 
|  void | setVerticalGroup(GroupLayout.Group group)Sets the Groupthat is responsible for
 layout along the vertical axis. | 
|  java.lang.String | toString()Returns a textual description of this GroupLayout. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
public static final int HORIZONTAL
linkSize(java.awt.Component[],int), 
Constant Field Valuespublic static final int VERTICAL
linkSize(java.awt.Component[],int), 
Constant Field Valuespublic static final int LEADING
createParallelGroup(int), 
Constant Field Valuespublic static final int TRAILING
createParallelGroup(int), 
Constant Field Valuespublic static final int CENTER
createParallelGroup(int), 
Constant Field Valuespublic static final int BASELINE
createParallelGroup(int), 
Constant Field Valuespublic static final int DEFAULT_SIZE
public static final int PREFERRED_SIZE
| Constructor Detail | 
|---|
public GroupLayout(java.awt.Container host)
host - the Container to layout
java.lang.IllegalArgumentException - if host is null| Method Detail | 
|---|
public void setHonorsVisibility(boolean honorsVisibility)
true indicates that
 non-visible components should not be treated as part of the
 layout. A value of false indicates that components should be
 positioned and sized regardless of visibility.
 
 A value of false is useful when the visibility of components
 is dynamically adjusted and you don't want surrounding components and
 the sizing to change.
 
The specified value is used for components that do not have an explicit visibility specified.
 The default is true.
honorsVisibility - whether component visiblity is considered when
                         sizing and positioning componentssetHonorsVisibility(Component,Boolean)public boolean getHonorsVisibility()
public void setHonorsVisibility(java.awt.Component component,
                                java.lang.Boolean honorsVisibility)
Boolean.TRUE
 indicates that if component is not visible it should
 not be treated as part of the layout. A value of false
 indicates that component is positioned and sized
 regardless of it's visibility.  A value of null
 indicates the value specified by the single argument method 
 setHonorsVisibility should be used.
 
 If component is not a child of the Container this
 GroupLayout is managing, it will be added to the
 Container.
component - the componenthonorsVisibility - whether component's visiblity should be
              considered for sizing and positioning
java.lang.IllegalArgumentException - if component is nullsetHonorsVisibility(boolean)public java.lang.String toString()
toString in class java.lang.Objectpublic void setAutocreateGaps(boolean autocreatePadding)
SequentialGroup a
 gap between the two will automatically be created.  The default
 is false.
autocreatePadding - whether or not to automatically created a gap
        between components and the containerpublic boolean getAutocreateGaps()
public void setAutocreateContainerGaps(boolean autocreatePadding)
autocreatePadding - whether or not to automatically create
        gaps between the container and first/last components.public boolean getAutocreateContainerGaps()
public void setHorizontalGroup(GroupLayout.Group group)
Group that is responsible for
 layout along the horizontal axis.
group - Group responsible for layout along
          the horizontal axis
java.lang.IllegalArgumentException - if group is nullpublic GroupLayout.Group getHorizontalGroup()
Group that is responsible for
 layout along the horizontal axis.
ParallelGroup responsible for layout along
          the horizontal axis.public void setVerticalGroup(GroupLayout.Group group)
Group that is responsible for
 layout along the vertical axis.
group - Group responsible for layout along
          the vertical axis.
java.lang.IllegalArgumentException - if group is null.public GroupLayout.Group getVerticalGroup()
ParallelGroup that is responsible for
 layout along the vertical axis.
ParallelGroup responsible for layout along
          the vertical axis.public GroupLayout.SequentialGroup createSequentialGroup()
SequentialGroup.
SequentialGrouppublic GroupLayout.ParallelGroup createParallelGroup()
ParallelGroup with a
 LEADING alignment.  This is a cover method for the more
 general createParallelGroup(int) method.
createParallelGroup(int)public GroupLayout.ParallelGroup createParallelGroup(int alignment)
ParallelGroup.  The alignment
 specifies how children elements should be positioned when the
 the parallel group is given more space than necessary.  For example,
 if a ParallelGroup with an alignment of TRAILING is given 100 pixels
 and a child only needs 50 pixels, the child will be positioned at the
 position 50.
alignment - alignment for the elements of the Group, one
        of LEADING, TRAILING,
        CENTER or BASELINE.
ParallelGroup
java.lang.IllegalArgumentException - if alignment is not one of
         LEADING, TRAILING,
         CENTER or BASELINE
public GroupLayout.ParallelGroup createParallelGroup(int alignment,
                                                     boolean resizable)
ParallelGroup.  The alignment
 specifies how children elements should be positioned when the
 the parallel group is given more space than necessary.  For example,
 if a ParallelGroup with an alignment of TRAILING is given 100 pixels
 and a child only needs 50 pixels, the child will be positioned at the
 position 50.
alignment - alignment for the elements of the Group, one
        of LEADING, TRAILING,
        CENTER or BASELINE.resizable - whether or not the group is resizable.  If the group
        is not resizable the min/max size will be the same as the
        preferred.
ParallelGroup
java.lang.IllegalArgumentException - if alignment is not one of
         LEADING, TRAILING,
         CENTER or BASELINE
public GroupLayout.ParallelGroup createBaselineGroup(boolean resizable,
                                                     boolean anchorBaselineToTop)
ParallelGroup that aligns it's
 elements along the baseline.
resizable - whether the group is resizableanchorBaselineToTop - whether the baseline is anchored to
        the top or bottom of the groupcreateBaselineGroup(boolean, boolean), 
GroupLayout.ParallelGrouppublic void linkSize(java.awt.Component[] components)
Linked Components are not be resizable.
components - Components to force to have same size.
java.lang.IllegalArgumentException - if components is
         null, or contains null.
public void linkSize(java.awt.Component[] components,
                     int axis)
Linked Components are not be resizable.
components - Components to force to have same size.axis - Axis to bind size, one of HORIZONTAL, VERTICAL or
             HORIZONTAL | VERTICAL
java.lang.IllegalArgumentException - if components is
         null, or contains null.
java.lang.IllegalArgumentException - if axis does not
         contain HORIZONTAL or VERTICAL
public void replace(java.awt.Component existingComponent,
                    java.awt.Component newComponent)
existingComponent - the Component that should be removed and
        replaced with newComponentnewComponent - the Component to put in existingComponents place
java.lang.IllegalArgumentException - is either of the Components are null or
         if existingComponent is not being managed by this layout managerpublic void setLayoutStyle(LayoutStyle layoutStyle)
layoutStyle - the LayoutStyle to usepublic LayoutStyle getLayoutStyle()
public void addLayoutComponent(java.lang.String name,
                               java.awt.Component component)
Component has been added to
 the parent container.  Developers should not invoke this method
 directly, instead you should use one of the Group
 methods to add a Component.
addLayoutComponent in interface java.awt.LayoutManagername - the string to be associated with the componentcomponent - the Component to be addedpublic void removeLayoutComponent(java.awt.Component component)
Component has been removed from
 the parent container.  You should not invoke this method
 directly, instead invoke remove on the parent
 Container.
removeLayoutComponent in interface java.awt.LayoutManagercomponent - the component to be removedComponent.remove(java.awt.MenuComponent)public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
preferredLayoutSize in interface java.awt.LayoutManagerparent - the container to return size for
java.lang.IllegalArgumentException - if parent is not
         the same Container that this was created with
java.lang.IllegalStateException - if any of the components added to
         this layout are not in both a horizontal and vertical groupContainer.getPreferredSize()public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
minimumLayoutSize in interface java.awt.LayoutManagerparent - the container to return size for
java.lang.IllegalArgumentException - if parent is not
         the same Container that this was created with
java.lang.IllegalStateException - if any of the components added to
         this layout are not in both a horizontal and vertical groupContainer.getMinimumSize()public void layoutContainer(java.awt.Container parent)
layoutContainer in interface java.awt.LayoutManagerparent - the container to be laid out
java.lang.IllegalStateException - if any of the components added to
         this layout are not in both a horizontal and vertical group
public void addLayoutComponent(java.awt.Component component,
                               java.lang.Object constraints)
Component has been added to
 the parent container.  You should not invoke this method
 directly, instead you should use one of the Group
 methods to add a Component.
addLayoutComponent in interface java.awt.LayoutManager2component - The component addedconstraints - Description of where to place the component.public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
maximumLayoutSize in interface java.awt.LayoutManager2parent - the container to return size for
java.lang.IllegalArgumentException - if parent is not
         the same Container that this was created with
java.lang.IllegalStateException - if any of the components added to
         this layout are not in both a horizontal and vertical groupContainer.getMaximumSize()public float getLayoutAlignmentX(java.awt.Container parent)
getLayoutAlignmentX in interface java.awt.LayoutManager2parent - Container hosting this LayoutManager
java.lang.IllegalArgumentException - if parent is not
         the same Container that this was created withpublic float getLayoutAlignmentY(java.awt.Container parent)
getLayoutAlignmentY in interface java.awt.LayoutManager2parent - Container hosting this LayoutManager
java.lang.IllegalArgumentException - if parent is not
         the same Container that this was created withpublic void invalidateLayout(java.awt.Container parent)
invalidateLayout in interface java.awt.LayoutManager2parent - Container hosting this LayoutManager
java.lang.IllegalArgumentException - if parent is not
         the same Container that this was created with| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||