public class SpringLayout extends java.lang.Object implements java.awt.LayoutManager2
Springs. You can attach a Spring for each edge of a component and
link it to an edge of a different component. For example, you can say,
the northern edge of component A should be attached to the southern edge
of component B, and the space between them should be something between
x and y pixels, and preferably z pixels.
While quite simple, this layout manager can be used to emulate most other layout managers, and can also be used to solve some layout problems, which would be hard to solve with other layout managers.
| Modifier and Type | Class and Description |
|---|---|
static class |
SpringLayout.Constraints
The constraints that define the relationships between components.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
EAST
The right edge of a component.
|
static java.lang.String |
NORTH
The top edge of a component.
|
static java.lang.String |
SOUTH
The bottom edge of a component.
|
static java.lang.String |
WEST
The left edge of a component.
|
| Constructor and Description |
|---|
SpringLayout()
Creates a new SpringLayout.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLayoutComponent(java.awt.Component component,
java.lang.Object constraint)
Adds a layout component and a constraint object to this layout.
|
void |
addLayoutComponent(java.lang.String name,
java.awt.Component c)
Adds a layout component and a constraint object to this layout.
|
Spring |
getConstraint(java.lang.String edgeName,
java.awt.Component c)
Returns the constraint of the edge named by
edgeName. |
SpringLayout.Constraints |
getConstraints(java.awt.Component c)
Returns the
SpringLayout.Constraints object associated with the specified
component. |
float |
getLayoutAlignmentX(java.awt.Container p)
Returns the X alignment of the Container
p. |
float |
getLayoutAlignmentY(java.awt.Container p)
Returns the Y alignment of the Container
p. |
void |
invalidateLayout(java.awt.Container p)
Recalculate a possibly cached layout.
|
void |
layoutContainer(java.awt.Container p)
Lays out the container
p. |
java.awt.Dimension |
maximumLayoutSize(java.awt.Container p)
Calculates the maximum size of the layed out container.
|
java.awt.Dimension |
minimumLayoutSize(java.awt.Container p)
Calculates the minimum size of the layed out container.
|
java.awt.Dimension |
preferredLayoutSize(java.awt.Container p)
Calculates the preferred size of the layed out container.
|
void |
putConstraint(java.lang.String e1,
java.awt.Component c1,
int pad,
java.lang.String e2,
java.awt.Component c2)
Attaches the edge
e1 of component c1 to
the edge e2 of component c2 width the
fixed strut pad. |
void |
putConstraint(java.lang.String e1,
java.awt.Component c1,
Spring s,
java.lang.String e2,
java.awt.Component c2)
|
void |
removeLayoutComponent(java.awt.Component c)
Removes a layout component.
|
public static final java.lang.String EAST
public static final java.lang.String NORTH
public static final java.lang.String SOUTH
public static final java.lang.String WEST
public SpringLayout()
public void addLayoutComponent(java.awt.Component component, java.lang.Object constraint)
Containers add
method.addLayoutComponent in interface java.awt.LayoutManager2component - the component to be added.constraint - the constraint to be set.public void addLayoutComponent(java.lang.String name, java.awt.Component c)
Containers add
method. This method does nothing, since SpringLayout does not manage
String-indexed components.addLayoutComponent in interface java.awt.LayoutManagername - the name.c - the component to be added.public Spring getConstraint(java.lang.String edgeName, java.awt.Component c)
edgeName.public SpringLayout.Constraints getConstraints(java.awt.Component c)
SpringLayout.Constraints object associated with the specified
component.c - the component for which to determine the constraint.SpringLayout.Constraints object associated with the specified
component.public float getLayoutAlignmentX(java.awt.Container p)
p.getLayoutAlignmentX in interface java.awt.LayoutManager2p - the Container for which to determine the X
alignment.public float getLayoutAlignmentY(java.awt.Container p)
p.getLayoutAlignmentY in interface java.awt.LayoutManager2p - the Container for which to determine the Y
alignment.public void invalidateLayout(java.awt.Container p)
invalidateLayout in interface java.awt.LayoutManager2p - the target containerpublic void layoutContainer(java.awt.Container p)
p.layoutContainer in interface java.awt.LayoutManagerp - the container to be laid out.public java.awt.Dimension maximumLayoutSize(java.awt.Container p)
maximumLayoutSize in interface java.awt.LayoutManager2p - the container to be laid out.Component.getMaximumSize()public java.awt.Dimension minimumLayoutSize(java.awt.Container p)
minimumLayoutSize in interface java.awt.LayoutManagerp - the container to be laid out.LayoutManager.preferredLayoutSize(Container)public java.awt.Dimension preferredLayoutSize(java.awt.Container p)
preferredLayoutSize in interface java.awt.LayoutManagerp - the container to be laid out.LayoutManager.minimumLayoutSize(Container)public void putConstraint(java.lang.String e1, java.awt.Component c1, int pad, java.lang.String e2, java.awt.Component c2)
e1 of component c1 to
the edge e2 of component c2 width the
fixed strut pad.e1 - the edge of component 1.c1 - the component 1.pad - the space between the components in pixels.e2 - the edge of component 2.c2 - the component 2.public void putConstraint(java.lang.String e1, java.awt.Component c1, Spring s, java.lang.String e2, java.awt.Component c2)
e1 - the edge of component 1.c1 - the component 1.s - the space between the components as a Spring object.e2 - the edge of component 2.c2 - the component 2.public void removeLayoutComponent(java.awt.Component c)
removeLayoutComponent in interface java.awt.LayoutManagerc - the layout component to remove.