- java.lang.Object
-
- net.miginfocom.swing.MigLayout
-
- All Implemented Interfaces:
java.awt.LayoutManager,java.awt.LayoutManager2,java.io.Externalizable,java.io.Serializable
public class MigLayout extends java.lang.Object implements java.awt.LayoutManager2, java.io.ExternalizableA very flexible layout manager.Read the documentation that came with this layout manager for information on usage.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMigLayout.MyDebugRepaintListener
-
Field Summary
Fields Modifier and Type Field Description private ContainerWrappercacheParentWprivate java.util.ArrayList<LayoutCallback>callbackListprivate java.util.Map<ComponentWrapper,CC>ccMapprivate java.lang.ObjectcolConstraintsHold the serializable text representation of the constraints.private ACcolSpecsprivate javax.swing.TimerdebugTimerprivate booleandirtyprivate Gridgridprivate intlastHashprivate java.awt.DimensionlastInvalidSizeprivate intlastModCountprivate java.awt.DimensionlastParentSizeprivate longlastSizeprivate booleanlastWasInvalidprivate java.lang.ObjectlayoutConstraintsHold the serializable text representation of the constraints.private LClcprivate java.lang.ObjectrowConstraintsHold the serializable text representation of the constraints.private ACrowSpecsprivate java.util.Map<java.awt.Component,java.lang.Object>scrConstrMapThe component to string constraints mappings.
-
Constructor Summary
Constructors Constructor Description MigLayout()Constructor with no constraints.MigLayout(java.lang.String layoutConstraints)Constructor.MigLayout(java.lang.String layoutConstraints, java.lang.String colConstraints)Constructor.MigLayout(java.lang.String layoutConstraints, java.lang.String colConstraints, java.lang.String rowConstraints)Constructor.MigLayout(LC layoutConstraints)Constructor.MigLayout(LC layoutConstraints, AC colConstraints)Constructor.MigLayout(LC layoutConstraints, AC colConstraints, AC rowConstraints)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLayoutCallback(LayoutCallback callback)Adds the callback function that will be called at different stages of the layout cycle.voidaddLayoutComponent(java.awt.Component comp, java.lang.Object constraints)voidaddLayoutComponent(java.lang.String s, java.awt.Component comp)private voidadjustWindowSize(ContainerWrapper parent)Checks the parent window/popup if its size is within parameters as set by the LC.private voidcheckCache(java.awt.Container parent)Check if something has changed and if so recreate it to the cached objects.private ContainerWrappercheckParent(java.awt.Container parent)private voidcleanConstraintMaps(java.awt.Container parent)Checks so all components in ccMap actually exist in the parent's collection.private intconstrain(ContainerWrapper parent, int winSize, int prefSize, BoundSize constrain)static <E> EfindType(java.lang.Class<E> clazz, java.awt.Component comp)java.lang.ObjectgetColumnConstraints()Returns the column layout constraints either as aStringorAC.java.lang.ObjectgetComponentConstraints(java.awt.Component comp)Returns the component constraints as a String representation.java.util.Map<java.awt.Component,java.lang.Object>getConstraintMap()Returns a shallow copy of the constraints map.private booleangetDebug()Returns the current debugging state.private intgetDebugMillis()Returns the debug millis.floatgetLayoutAlignmentX(java.awt.Container parent)floatgetLayoutAlignmentY(java.awt.Container parent)java.lang.ObjectgetLayoutConstraints()Returns layout constraints either as aStringorLCdepending what was sent in to the constructor or set withsetLayoutConstraints(Object).private java.awt.ContainergetPackable(java.awt.Component comp)Returns a high level window or popup to pack, if any.java.lang.ObjectgetRowConstraints()Returns the row layout constraints either as aStringorAC.private java.awt.DimensiongetSizeImpl(java.awt.Container parent, int sizeType)voidinvalidateLayout(java.awt.Container target)booleanisManagingComponent(java.awt.Component c)Returns if this layout manager is currently managing this component.voidlayoutContainer(java.awt.Container parent)java.awt.DimensionmaximumLayoutSize(java.awt.Container parent)java.awt.DimensionminimumLayoutSize(java.awt.Container parent)java.awt.DimensionpreferredLayoutSize(java.awt.Container parent)voidreadExternal(java.io.ObjectInput in)private java.lang.ObjectreadResolve()voidremoveLayoutCallback(LayoutCallback callback)Removes the callback if it exists.voidremoveLayoutComponent(java.awt.Component comp)private voidresetLastInvalidOnParent(java.awt.Container parent)voidsetColumnConstraints(java.lang.Object constr)Sets the column layout constraints for the layout manager instance as a String.voidsetComponentConstraints(java.awt.Component comp, java.lang.Object constr)Sets the component constraint for the component that already must be handled by this layout manager.private voidsetComponentConstraintsImpl(java.awt.Component comp, java.lang.Object constr, boolean noCheck)Sets the component constraint for the component that already must be handled by this layout manager.voidsetConstraintMap(java.util.Map<java.awt.Component,java.lang.Object> map)Sets the constraints map.private voidsetDebug(ComponentWrapper parentW, boolean b)Sets the debugging state for this layout manager instance.voidsetLayoutConstraints(java.lang.Object constr)Sets the layout constraints for the layout manager instance as a String.voidsetRowConstraints(java.lang.Object constr)Sets the row layout constraints for the layout manager instance as a String.voidwriteExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
scrConstrMap
private final java.util.Map<java.awt.Component,java.lang.Object> scrConstrMap
The component to string constraints mappings.
-
layoutConstraints
private java.lang.Object layoutConstraints
Hold the serializable text representation of the constraints.
-
colConstraints
private java.lang.Object colConstraints
Hold the serializable text representation of the constraints.
-
rowConstraints
private java.lang.Object rowConstraints
Hold the serializable text representation of the constraints.
-
cacheParentW
private transient ContainerWrapper cacheParentW
-
ccMap
private final transient java.util.Map<ComponentWrapper,CC> ccMap
-
debugTimer
private transient javax.swing.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 java.awt.Dimension lastInvalidSize
-
lastWasInvalid
private transient boolean lastWasInvalid
-
lastParentSize
private transient java.awt.Dimension lastParentSize
-
callbackList
private transient java.util.ArrayList<LayoutCallback> callbackList
-
dirty
private transient boolean dirty
-
lastSize
private long lastSize
-
-
Constructor Detail
-
MigLayout
public MigLayout()
Constructor with no constraints.
-
MigLayout
public MigLayout(java.lang.String layoutConstraints)
Constructor.- Parameters:
layoutConstraints- The constraints that concern the whole layout.nullwill be treated as "".
-
MigLayout
public MigLayout(java.lang.String layoutConstraints, java.lang.String colConstraints)Constructor.- Parameters:
layoutConstraints- The constraints that concern the whole layout.nullwill be treated as "".colConstraints- The constraints for the columns in the grid.nullwill be treated as "".
-
MigLayout
public MigLayout(java.lang.String layoutConstraints, java.lang.String colConstraints, java.lang.String rowConstraints)Constructor.- Parameters:
layoutConstraints- The constraints that concern the whole layout.nullwill be treated as "".colConstraints- The constraints for the columns in the grid.nullwill be treated as "".rowConstraints- The constraints for the rows in the grid.nullwill be treated as "".
-
MigLayout
public MigLayout(LC layoutConstraints)
Constructor.- Parameters:
layoutConstraints- The constraints that concern the whole layout.nullwill be treated as an empty constraint.
-
MigLayout
public MigLayout(LC layoutConstraints, AC colConstraints)
Constructor.- Parameters:
layoutConstraints- The constraints that concern the whole layout.nullwill be treated as an empty constraint.colConstraints- The constraints for the columns in the grid.nullwill 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.nullwill be treated as an empty constraint.colConstraints- The constraints for the columns in the grid.nullwill be treated as an empty constraint.rowConstraints- The constraints for the rows in the grid.nullwill be treated as an empty constraint.
-
-
Method Detail
-
getLayoutConstraints
public java.lang.Object getLayoutConstraints()
Returns layout constraints either as aStringorLCdepending what was sent in to the constructor or set withsetLayoutConstraints(Object).- Returns:
- The layout constraints either as a
StringorLCdepending what was sent in to the constructor or set withsetLayoutConstraints(Object). Nevernull.
-
setLayoutConstraints
public void setLayoutConstraints(java.lang.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 orLCrepresentation.nullis converted to""for storage.- Throws:
java.lang.RuntimeException- if the constraint was not valid.
-
getColumnConstraints
public java.lang.Object getColumnConstraints()
Returns the column layout constraints either as aStringorAC.- Returns:
- The column constraints either as a
StringorACdepending what was sent in to the constructor or set withsetColumnConstraints(Object). Nevernull.
-
setColumnConstraints
public void setColumnConstraints(java.lang.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 orACrepresentation.nullis converted to""for storage.- Throws:
java.lang.RuntimeException- if the constraint was not valid.
-
getRowConstraints
public java.lang.Object getRowConstraints()
Returns the row layout constraints either as aStringorAC.- Returns:
- The row constraints either as a
StringorACdepending what was sent in to the constructor or set withsetRowConstraints(Object). Nevernull.
-
setRowConstraints
public void setRowConstraints(java.lang.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 orACrepresentation.nullis converted to""for storage.- Throws:
java.lang.RuntimeException- if the constraint was not valid.
-
getConstraintMap
public java.util.Map<java.awt.Component,java.lang.Object> getConstraintMap()
Returns a shallow copy of the constraints map.- Returns:
- A shallow copy of the constraints map. Never
null.
-
setConstraintMap
public void setConstraintMap(java.util.Map<java.awt.Component,java.lang.Object> map)
Sets the constraints map.- Parameters:
map- The map. Will be copied.
-
getComponentConstraints
public java.lang.Object getComponentConstraints(java.awt.Component comp)
Returns the component constraints as a String representation. This string is the exact string as set withsetComponentConstraints(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
nullif the component is not registered with this layout manager. The returned values is either a String or aCCdepending on what constraint was sent in when the component was added. May benull.
-
setComponentConstraints
public void setComponentConstraints(java.awt.Component comp, java.lang.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:
constr- The component constraints as a String orCC.nullis ok.comp- The component to set the constraints for.- Throws:
java.lang.RuntimeException- if the constraint was not valid.java.lang.IllegalArgumentException- If the component is not handling the component.
-
setComponentConstraintsImpl
private void setComponentConstraintsImpl(java.awt.Component comp, java.lang.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:
constr- The component constraints as a String orCC.nullis ok.comp- The component to set the constraints for.noCheck- Does not check if the component is handled if true- Throws:
java.lang.RuntimeException- if the constraint was not valid.java.lang.IllegalArgumentException- If the component is not handling the component.
-
isManagingComponent
public boolean isManagingComponent(java.awt.Component c)
Returns if this layout manager is currently managing this component.- Parameters:
c- The component to check. Ifnullthenfalsewill 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. Notnull.
-
removeLayoutCallback
public void removeLayoutCallback(LayoutCallback callback)
Removes the callback if it exists.- Parameters:
callback- The callback. May benull.
-
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-truemeans 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 fromLC.getDebugMillis()andLayoutUtil.getGlobalDebugMillis()- Returns:
- The combined value.
-
checkCache
private void checkCache(java.awt.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(java.awt.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(java.awt.Container parent)
- Since:
- 3.7.3
-
checkParent
private ContainerWrapper checkParent(java.awt.Container parent)
-
layoutContainer
public void layoutContainer(java.awt.Container parent)
- Specified by:
layoutContainerin interfacejava.awt.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 java.awt.Container getPackable(java.awt.Component comp)
Returns a high level window or popup to pack, if any.- Returns:
- May be null.
-
findType
public static <E> E findType(java.lang.Class<E> clazz, java.awt.Component comp)
-
constrain
private int constrain(ContainerWrapper parent, int winSize, int prefSize, BoundSize constrain)
-
minimumLayoutSize
public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
- Specified by:
minimumLayoutSizein interfacejava.awt.LayoutManager
-
preferredLayoutSize
public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
- Specified by:
preferredLayoutSizein interfacejava.awt.LayoutManager
-
maximumLayoutSize
public java.awt.Dimension maximumLayoutSize(java.awt.Container parent)
- Specified by:
maximumLayoutSizein interfacejava.awt.LayoutManager2
-
getSizeImpl
private java.awt.Dimension getSizeImpl(java.awt.Container parent, int sizeType)
-
getLayoutAlignmentX
public float getLayoutAlignmentX(java.awt.Container parent)
- Specified by:
getLayoutAlignmentXin interfacejava.awt.LayoutManager2
-
getLayoutAlignmentY
public float getLayoutAlignmentY(java.awt.Container parent)
- Specified by:
getLayoutAlignmentYin interfacejava.awt.LayoutManager2
-
addLayoutComponent
public void addLayoutComponent(java.lang.String s, java.awt.Component comp)- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager
-
addLayoutComponent
public void addLayoutComponent(java.awt.Component comp, java.lang.Object constraints)- Specified by:
addLayoutComponentin interfacejava.awt.LayoutManager2
-
removeLayoutComponent
public void removeLayoutComponent(java.awt.Component comp)
- Specified by:
removeLayoutComponentin interfacejava.awt.LayoutManager
-
invalidateLayout
public void invalidateLayout(java.awt.Container target)
- Specified by:
invalidateLayoutin interfacejava.awt.LayoutManager2
-
readResolve
private java.lang.Object readResolve() throws java.io.ObjectStreamException- Throws:
java.io.ObjectStreamException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
-