All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.swing.SpringLayout
java.lang.Object
|
+----java.awt.swing.SpringLayout
- public class SpringLayout
- extends Object
- implements LayoutManager2, Serializable
Simple Springs and Struts LayoutManager.
The _CAN_CHANGE values can be or-ed together to specify all the
springs for a component. For example:
layout.setSprings(widget, SpringLayout.RIGHT_MARGIN_CAN_CHANGE
| SpringLayout.TOP_MARGIN_CAN_CHANGE));
or
parent.add(child, SpringLayout.RIGHT_TOP_SPRINGS);
Space will be evenly distributed among all springs along a single
axis. i.e. If you have set the springs such that
RIGHT_MARGIN_CAN_CHANGE | LEFT_MARGIN_CAN_CHANGE and the parent
grows by 10 pixels in the x dimension, the left and right margins
of the child will each grow by 5 pixels.
This layout manager does not determine default sizes for
components. It simply allocates changes in space to the components
as appropriate. To properly utilize this LayoutManager, you should
specify the bounds of the Components prior to placing them in the
view hierarchy. When the parent's bounds change, the children will
have their bounds changed accoordingly.
The current implementation manages the springs as a set of
integer values. You may pass an Integer object as a constraint to
the add(component, constraint) method of Container. For example:
parent.add(child, new Integer(SpringLayout.RIGHT_MARGIN_CAN_CHANGE
| SpringLayout.TOP_MARGIN_CAN_CHANGE));
Using the createSpring() is the preferred manner of getting
a properly configured constraint object.
SpringLayout.SpringValues-
BOTTOM_LEFT_SPRINGS- Convience constraint object.
BOTTOM_MARGIN_CAN_CHANGE- Indicates that the space to the bottom of widget will
grow and shrink as the parent component changes size.
BOTTOM_RIGHT_SPRINGS- Convience constraint object.
BOTTOM_SPRING- Convience constraint object.
CENTER_HORIZ_SPRINGS- Convience constraint object.
CENTER_VERT_SPRINGS- Convience constraint object.
componentAttributes-
HEIGHT_CAN_CHANGE- Indicates that the height of the widget will
grow and shrink as the parent component changes size.
HEIGHT_SPRING- Convience constraint object.
HEIGHT_WIDTH_SPRING- Convience constraint object.
HW_SPRINGS_MASK-
LEFT_MARGIN_CAN_CHANGE- Indicates that the space to the left of widget will
grow and shrink as the parent component changes size.
LEFT_SPRING- Convience constraint object.
noticeBoundsChanged-
ORIGINAL_BOUNDS_KEY- This is the key used in the object properties list to store the
orginal bounds of the component.
RIGHT_MARGIN_CAN_CHANGE- Indicates that the space to the right of widget will
grow and shrink as the parent component changes size.
RIGHT_SPRING- Convience constraint object.
SPRINGS_KEY- This is the key used in the object properties list to store the
springs value.
TOP_LEFT_SPRINGS- Convience constraint object.
TOP_MARGIN_CAN_CHANGE- Indicates that the space to the top of widget will
grow and shrink as the parent component changes size.
TOP_RIGHT_SPRINGS- Convience constraint object.
TOP_SPRING- Convience constraint object.
VALIDITY_MASK-
WIDTH_CAN_CHANGE- Indicates that the width of the widget will
grow and shrink as the parent component changes size.
WIDTH_SPRING- Convience constraint object.
SpringLayout()
-
addLayoutComponent(Component, Object)
- If constraints is a valid spring object (as returned from
createSpring()) then these constraints will be set on the
comp.
addLayoutComponent(String, Component)
-
createSpring(int)
- Returns an Integer used for storing springs in data structures
needing objects.
getLayoutAlignmentX(Container)
- Returns the target's alignment x.
getLayoutAlignmentY(Container)
- Returns the target's alignment y.
getSprings(Component)
- Returns the current spring settings for this container.
horizontalSpringCount(int)
-
invalidateLayout(Container)
-
isValidSpring(int)
- Returns false if spring is not a valid combination of springs.
layoutContainer(Container)
- Performs the actual layout of the component based on their spring settings.
maximumLayoutSize(Container)
- Returns the target's maximum size.
minimumLayoutSize(Container)
- Returns the parent's minimum size.
originalBoundsFor(Component)
-
preferredLayoutSize(Container)
- Returns the parent's size.
removeLayoutComponent(Component)
-
resetOriginalBounds(Container)
- The first time the parent is asked to layout, it's bounds
and the bounds of it's immediate children are cached.
setSprings(Component, int)
- Sets the springs values for this container.
storeOriginalBoundsFor(Component, Rectangle)
-
verticalSpringCount(int)
-
RIGHT_MARGIN_CAN_CHANGE
public static final int RIGHT_MARGIN_CAN_CHANGE
- Indicates that the space to the right of widget will
grow and shrink as the parent component changes size.
LEFT_MARGIN_CAN_CHANGE
public static final int LEFT_MARGIN_CAN_CHANGE
- Indicates that the space to the left of widget will
grow and shrink as the parent component changes size.
TOP_MARGIN_CAN_CHANGE
public static final int TOP_MARGIN_CAN_CHANGE
- Indicates that the space to the top of widget will
grow and shrink as the parent component changes size.
BOTTOM_MARGIN_CAN_CHANGE
public static final int BOTTOM_MARGIN_CAN_CHANGE
- Indicates that the space to the bottom of widget will
grow and shrink as the parent component changes size.
WIDTH_CAN_CHANGE
public static final int WIDTH_CAN_CHANGE
- Indicates that the width of the widget will
grow and shrink as the parent component changes size.
HEIGHT_CAN_CHANGE
public static final int HEIGHT_CAN_CHANGE
- Indicates that the height of the widget will
grow and shrink as the parent component changes size.
HW_SPRINGS_MASK
protected static final int HW_SPRINGS_MASK
VALIDITY_MASK
protected static final int VALIDITY_MASK
RIGHT_SPRING
public static final Integer RIGHT_SPRING
- Convience constraint object. Equivalent to RIGHT_MARGIN_CAN_CHANGE.
LEFT_SPRING
public static final Integer LEFT_SPRING
- Convience constraint object. Equivalent to LEFT_MARGIN_CAN_CHANGE.
TOP_SPRING
public static final Integer TOP_SPRING
- Convience constraint object. Equivalent to TOP_MARGIN_CAN_CHANGE.
BOTTOM_SPRING
public static final Integer BOTTOM_SPRING
- Convience constraint object. Equivalent to BOTTOM_MARGIN_CAN_CHANGE.
WIDTH_SPRING
public static final Integer WIDTH_SPRING
- Convience constraint object. Equivalent to WIDTH_CAN_CHANGE.
HEIGHT_SPRING
public static final Integer HEIGHT_SPRING
- Convience constraint object. Equivalent to HEIGHT_CAN_CHANGE.
HEIGHT_WIDTH_SPRING
public static final Integer HEIGHT_WIDTH_SPRING
- Convience constraint object. Equivalent to HEIGHT_CAN_CHANGE | WIDTH_CAN_CHANGE.
CENTER_HORIZ_SPRINGS
public static final Integer CENTER_HORIZ_SPRINGS
- Convience constraint object. Equivalent to LEFT_MARGIN_CAN_CHANGE | RIGHT_MARGIN_CAN_CHANGE.
CENTER_VERT_SPRINGS
public static final Integer CENTER_VERT_SPRINGS
- Convience constraint object. Equivalent to TOP_MARGIN_CAN_CHANGE | BOTTOM_MARGIN_CAN_CHANGE.
BOTTOM_LEFT_SPRINGS
public static final Integer BOTTOM_LEFT_SPRINGS
- Convience constraint object. Equivalent to LEFT_MARGIN_CAN_CHANGE | BOTTOM_MARGIN_CAN_CHANGE.
BOTTOM_RIGHT_SPRINGS
public static final Integer BOTTOM_RIGHT_SPRINGS
- Convience constraint object. Equivalent to RIGHT_MARGIN_CAN_CHANGE | BOTTOM_MARGIN_CAN_CHANGE.
TOP_RIGHT_SPRINGS
public static final Integer TOP_RIGHT_SPRINGS
- Convience constraint object. Equivalent to RIGHT_MARGIN_CAN_CHANGE | TOP_MARGIN_CAN_CHANGE.
TOP_LEFT_SPRINGS
public static final Integer TOP_LEFT_SPRINGS
- Convience constraint object. Equivalent to LEFT_MARGIN_CAN_CHANGE | TOP_MARGIN_CAN_CHANGE.
SPRINGS_KEY
protected static final String SPRINGS_KEY
- This is the key used in the object properties list to store the
springs value.
ORIGINAL_BOUNDS_KEY
protected static final String ORIGINAL_BOUNDS_KEY
- This is the key used in the object properties list to store the
orginal bounds of the component.
noticeBoundsChanged
protected boolean noticeBoundsChanged
componentAttributes
protected Hashtable componentAttributes
SpringLayout
public SpringLayout()
setSprings
public void setSprings(Component container,
int springs)
- Sets the springs values for this container.
springs must be a valid combination of the constants
defined, or this method will throw an IllegalArgumentException.
getSprings
public int getSprings(Component container)
- Returns the current spring settings for this container.
If no values have been set returns BOTTOM_RIGHT_SPRINGS.intValue().
createSpring
public static Integer createSpring(int spring)
- Returns an Integer used for storing springs in data structures
needing objects. Current implementation returns a shared instance
for common values. This object can be passed into the
add(component, constraint) method as a constraint.
isValidSpring
public boolean isValidSpring(int spring)
- Returns false if spring is not a valid combination of springs.
resetOriginalBounds
public void resetOriginalBounds(Container parent)
- The first time the parent is asked to layout, it's bounds
and the bounds of it's immediate children are cached. Changes in
size are calculated from this original bounds. Calling this method
causes the cache to be updated to the current bounds of the parent
and it's immediate children. This can be useful, if you have manually
adjusted the bounds of a view after it's already had layout called on it,
and you want all further calculations to use the updated values.
You normally won't need to call this method.
addLayoutComponent
public void addLayoutComponent(String name,
Component comp)
removeLayoutComponent
public void removeLayoutComponent(Component comp)
preferredLayoutSize
public Dimension preferredLayoutSize(Container parent)
- Returns the parent's size.
minimumLayoutSize
public Dimension minimumLayoutSize(Container parent)
- Returns the parent's minimum size.
layoutContainer
public void layoutContainer(Container parent)
- Performs the actual layout of the component based on their spring settings.
addLayoutComponent
public void addLayoutComponent(Component comp,
Object constraints)
- If constraints is a valid spring object (as returned from
createSpring()) then these constraints will be set on the
comp. Normally you will use setSprings() to accomplish this.
If constraints is invalid, this method throw an IllegalArgumentException.
maximumLayoutSize
public Dimension maximumLayoutSize(Container target)
- Returns the target's maximum size.
getLayoutAlignmentX
public float getLayoutAlignmentX(Container target)
- Returns the target's alignment x.
getLayoutAlignmentY
public float getLayoutAlignmentY(Container target)
- Returns the target's alignment y.
invalidateLayout
public void invalidateLayout(Container target)
verticalSpringCount
protected int verticalSpringCount(int springs)
horizontalSpringCount
protected int horizontalSpringCount(int springs)
originalBoundsFor
protected Rectangle originalBoundsFor(Component view)
storeOriginalBoundsFor
protected void storeOriginalBoundsFor(Component view,
Rectangle bounds)
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature