Class MigLayout

java.lang.Object
net.miginfocom.swing.MigLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Externalizable, Serializable

public class MigLayout extends Object implements LayoutManager2, Externalizable
A very flexible layout manager.

Read the documentation that came with this layout manager for information on usage.

See Also:
  • Field Details

    • scrConstrMap

      private final Map<Component,Object> scrConstrMap
      The component to string constraints mappings.
    • layoutConstraints

      private Object layoutConstraints
      Hold the serializable text representation of the constraints.
    • colConstraints

      private Object colConstraints
      Hold the serializable text representation of the constraints.
    • rowConstraints

      private Object rowConstraints
      Hold the serializable text representation of the constraints.
    • cacheParentW

      private transient ContainerWrapper cacheParentW
    • ccMap

      private final transient Map<ComponentWrapper,CC> ccMap
    • debugTimer

      private transient Timer debugTimer
    • lc

      private transient LC lc
    • colSpecs

      private transient AC colSpecs
    • rowSpecs

      private transient AC rowSpecs
    • grid

      private transient Grid grid
    • lastModCount

      private transient int lastModCount
    • lastHash

      private transient int lastHash
    • lastInvalidSize

      private transient Dimension lastInvalidSize
    • lastWasInvalid

      private transient boolean lastWasInvalid
    • lastParentSize

      private transient Dimension lastParentSize
    • callbackList

      private transient ArrayList<LayoutCallback> callbackList
    • dirty

      private transient boolean dirty
    • lastSize

      private long lastSize
  • Constructor Details

    • MigLayout

      public MigLayout()
      Constructor with no constraints.
    • MigLayout

      public MigLayout(String layoutConstraints)
      Constructor.
      Parameters:
      layoutConstraints - The constraints that concern the whole layout. null will be treated as "".
    • MigLayout

      public MigLayout(String layoutConstraints, String colConstraints)
      Constructor.
      Parameters:
      layoutConstraints - The constraints that concern the whole layout. null will be treated as "".
      colConstraints - The constraints for the columns in the grid. null will be treated as "".
    • MigLayout

      public MigLayout(String layoutConstraints, String colConstraints, String rowConstraints)
      Constructor.
      Parameters:
      layoutConstraints - The constraints that concern the whole layout. null will be treated as "".
      colConstraints - The constraints for the columns in the grid. null will be treated as "".
      rowConstraints - The constraints for the rows in the grid. null will be treated as "".
    • MigLayout

      public MigLayout(LC layoutConstraints)
      Constructor.
      Parameters:
      layoutConstraints - The constraints that concern the whole layout. null will be treated as an empty constraint.
    • MigLayout

      public MigLayout(LC layoutConstraints, AC colConstraints)
      Constructor.
      Parameters:
      layoutConstraints - The constraints that concern the whole layout. null will be treated as an empty constraint.
      colConstraints - The constraints for the columns in the grid. null will be treated as an empty constraint.
    • MigLayout

      public MigLayout(LC layoutConstraints, AC colConstraints, AC rowConstraints)
      Constructor.
      Parameters:
      layoutConstraints - The constraints that concern the whole layout. null will be treated as an empty constraint.
      colConstraints - The constraints for the columns in the grid. null will be treated as an empty constraint.
      rowConstraints - The constraints for the rows in the grid. null will be treated as an empty constraint.
  • Method Details

    • getLayoutConstraints

      public Object getLayoutConstraints()
      Returns layout constraints either as a String or LC depending what was sent in to the constructor or set with setLayoutConstraints(Object).
      Returns:
      The layout constraints either as a String or LC depending what was sent in to the constructor or set with setLayoutConstraints(Object). Never null.
    • setLayoutConstraints

      public void setLayoutConstraints(Object constr)
      Sets the layout constraints for the layout manager instance as a String.

      See the class JavaDocs for information on how this string is formatted.

      Parameters:
      constr - The layout constraints as a String or LC representation. null is converted to "" for storage.
      Throws:
      RuntimeException - if the constraint was not valid.
    • getColumnConstraints

      public Object getColumnConstraints()
      Returns the column layout constraints either as a String or AC.
      Returns:
      The column constraints either as a String or AC depending what was sent in to the constructor or set with setColumnConstraints(Object). Never null.
    • setColumnConstraints

      public void setColumnConstraints(Object constr)
      Sets the column layout constraints for the layout manager instance as a String.

      See the class JavaDocs for information on how this string is formatted.

      Parameters:
      constr - The column layout constraints as a String or AC representation. null is converted to "" for storage.
      Throws:
      RuntimeException - if the constraint was not valid.
    • getRowConstraints

      public Object getRowConstraints()
      Returns the row layout constraints either as a String or AC.
      Returns:
      The row constraints either as a String or AC depending what was sent in to the constructor or set with setRowConstraints(Object). Never null.
    • setRowConstraints

      public void setRowConstraints(Object constr)
      Sets the row layout constraints for the layout manager instance as a String.

      See the class JavaDocs for information on how this string is formatted.

      Parameters:
      constr - The row layout constraints as a String or AC representation. null is converted to "" for storage.
      Throws:
      RuntimeException - if the constraint was not valid.
    • getConstraintMap

      public Map<Component,Object> getConstraintMap()
      Returns a shallow copy of the constraints map.
      Returns:
      A shallow copy of the constraints map. Never null.
    • setConstraintMap

      public void setConstraintMap(Map<Component,Object> map)
      Sets the constraints map.
      Parameters:
      map - The map. Will be copied.
    • getComponentConstraints

      public Object getComponentConstraints(Component comp)
      Returns the component constraints as a String representation. This string is the exact string as set with setComponentConstraints(java.awt.Component, Object) or set when adding the component to the parent component.

      See the class JavaDocs for information on how this string is formatted.

      Parameters:
      comp - The component to return the constraints for.
      Returns:
      The component constraints as a String representation or null if the component is not registered with this layout manager. The returned values is either a String or a CC depending on what constraint was sent in when the component was added. May be null.
    • setComponentConstraints

      public void setComponentConstraints(Component comp, Object constr)
      Sets the component constraint for the component that already must be handled by this layout manager.

      See the class JavaDocs for information on how this string is formatted.

      Parameters:
      comp - The component to set the constraints for.
      constr - The component constraints as a String or CC. null is ok.
      Throws:
      RuntimeException - if the constraint was not valid.
      IllegalArgumentException - If the component is not handling the component.
    • setComponentConstraintsImpl

      private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck)
      Sets the component constraint for the component that already must be handled by this layout manager.

      See the class JavaDocs for information on how this string is formatted.

      Parameters:
      comp - The component to set the constraints for.
      constr - The component constraints as a String or CC. null is ok.
      noCheck - Does not check if the component is handled if true
      Throws:
      RuntimeException - if the constraint was not valid.
      IllegalArgumentException - If the component is not handling the component.
    • isManagingComponent

      public boolean isManagingComponent(Component c)
      Returns if this layout manager is currently managing this component.
      Parameters:
      c - The component to check. If null then false will be returned.
      Returns:
      If this layout manager is currently managing this component.
    • addLayoutCallback

      public void addLayoutCallback(LayoutCallback callback)
      Adds the callback function that will be called at different stages of the layout cycle.
      Parameters:
      callback - The callback. Not null.
    • removeLayoutCallback

      public void removeLayoutCallback(LayoutCallback callback)
      Removes the callback if it exists.
      Parameters:
      callback - The callback. May be null.
    • setDebug

      private void setDebug(ComponentWrapper parentW, boolean b)
      Sets the debugging state for this layout manager instance. If debug is turned on a timer will repaint the last laid out parent with debug information on top.

      Red fill and dashed red outline is used to indicate occupied cells in the grid. Blue dashed outline indicate component bounds set.

      Note that debug can also be set on the layout constraints. There it will be persisted. The value set here will not. See the class JavaDocs for information.

      Parameters:
      parentW - The parent to set debug for.
      b - true means debug is turned on.
    • getDebug

      private boolean getDebug()
      Returns the current debugging state.
      Returns:
      The current debugging state.
    • getDebugMillis

      private int getDebugMillis()
      Returns the debug millis. Combines the value from LC.getDebugMillis() and LayoutUtil.getGlobalDebugMillis()
      Returns:
      The combined value.
    • checkCache

      private void checkCache(Container parent)
      Check if something has changed and if so recreate it to the cached objects.
      Parameters:
      parent - The parent that is the target for this layout manager.
    • cleanConstraintMaps

      private void cleanConstraintMaps(Container parent)
      Checks so all components in ccMap actually exist in the parent's collection. Removes any references that don't.
      Parameters:
      parent - The parent to compare ccMap against. Never null.
    • resetLastInvalidOnParent

      private void resetLastInvalidOnParent(Container parent)
      Since:
      3.7.3
    • checkParent

      private ContainerWrapper checkParent(Container parent)
    • layoutContainer

      public void layoutContainer(Container parent)
      Specified by:
      layoutContainer in interface LayoutManager
    • adjustWindowSize

      private void adjustWindowSize(ContainerWrapper parent)
      Checks the parent window/popup if its size is within parameters as set by the LC.
      Parameters:
      parent - The parent who's window to possibly adjust the size for.
    • getPackable

      private Container getPackable(Component comp)
      Returns a high level window or popup to pack, if any.
      Returns:
      May be null.
    • findType

      public static <E> E findType(Class<E> clazz, Component comp)
    • constrain

      private int constrain(ContainerWrapper parent, int winSize, int prefSize, BoundSize constrain)
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container parent)
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Specified by:
      preferredLayoutSize in interface LayoutManager
    • maximumLayoutSize

      public Dimension maximumLayoutSize(Container parent)
      Specified by:
      maximumLayoutSize in interface LayoutManager2
    • getSizeImpl

      private Dimension getSizeImpl(Container parent, int sizeType)
    • getLayoutAlignmentX

      public float getLayoutAlignmentX(Container parent)
      Specified by:
      getLayoutAlignmentX in interface LayoutManager2
    • getLayoutAlignmentY

      public float getLayoutAlignmentY(Container parent)
      Specified by:
      getLayoutAlignmentY in interface LayoutManager2
    • addLayoutComponent

      public void addLayoutComponent(String s, Component comp)
      Specified by:
      addLayoutComponent in interface LayoutManager
    • addLayoutComponent

      public void addLayoutComponent(Component comp, Object constraints)
      Specified by:
      addLayoutComponent in interface LayoutManager2
    • removeLayoutComponent

      public void removeLayoutComponent(Component comp)
      Specified by:
      removeLayoutComponent in interface LayoutManager
    • invalidateLayout

      public void invalidateLayout(Container target)
      Specified by:
      invalidateLayout in interface LayoutManager2
    • readResolve

      private Object readResolve() throws ObjectStreamException
      Throws:
      ObjectStreamException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException