|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.SpringLayout.Constraints
A Constraints object holds the
constraints that govern the way a component's size and position
change in a container controlled by a SpringLayout.
A Constraints object is
like a Rectangle, in that it
has x, y,
width, and height properties.
In the Constraints object, however,
these properties have
Spring values instead of integers.
In addition,
a Constraints object
can be manipulated as four edges
-- north, south, east, and west --
using the constraint property.
The following formulas are always true
for a Constraints object:
west = x
north = y
east = x + width
south = y + height
Note: In this document,
operators represent methods
in the Spring class.
For example, "a + b" is equal to
Spring.sum(a, b),
and "a - b" is equal to
Spring.sum(a, Spring.minus(b)).
See the
Spring API documentation
for further details
of spring arithmetic.
Because a Constraints object's properties --
representing its edges, size, and location -- can all be set
independently and yet are interrelated,
the object can become over-constrained.
For example,
if both the x and width
properties are set
and then the east edge is set,
the object is over-constrained horizontally.
When this happens, one of the values
(in this case, the x property)
automatically changes so
that the formulas still hold.
The following table shows which value changes
when a Constraints object
is over-constrained horizontally.
| Value Being Set (method used) |
Result When Over-Constrained Horizontally ( x, width, and the east edge are all non-null) |
|---|---|
x or the west edge ( setX or setConstraint) |
width value is automatically set to east - x. |
width( setWidth) |
east edge's value is automatically set to x + width. |
| east edge ( setConstraint) |
x value is automatically set to east - width. |
The rules for the vertical properties are similar:
| Value Being Set (method used) |
Result When Over-Constrained Vertically ( y, height, and the south edge are all non-null) |
|---|---|
y or the north edge( setY or setConstraint) |
height value is automatically set to south - y. |
height( setHeight) |
south edge's value is automatically set to y + height. |
| south edge ( setConstraint) |
y value is automatically set to south - height. |
| Field Summary | |
private Spring |
east
|
private Spring |
height
|
private Spring |
horizontalDerived
|
private Spring |
south
|
private Spring |
verticalDerived
|
private Spring |
width
|
private Spring |
x
|
private Spring |
y
|
| Constructor Summary | |
SpringLayout.Constraints()
Creates an empty Constraints object. |
|
SpringLayout.Constraints(Spring x,
Spring y)
Creates a Constraints object with the
specified values for its
x and y properties.
|
|
SpringLayout.Constraints(Spring x,
Spring y,
Spring width,
Spring height)
Creates a Constraints object with the
specified values for its
x, y, width,
and height properties.
|
|
| Method Summary | |
private Spring |
difference(Spring s1,
Spring s2)
|
Spring |
getConstraint(String edgeName)
Returns the value of the specified edge. |
private Spring |
getEast()
|
Spring |
getHeight()
Returns the value of the height property. |
private Spring |
getSouth()
|
Spring |
getWidth()
Returns the value of the width property. |
Spring |
getX()
Returns the value of the x property. |
Spring |
getY()
Returns the value of the y property. |
private boolean |
overConstrainedHorizontally()
|
private boolean |
overConstrainedVertically()
|
(package private) void |
reset()
|
void |
setConstraint(String edgeName,
Spring s)
Sets the spring controlling the specified edge. |
private void |
setEast(Spring east)
|
void |
setHeight(Spring height)
Sets the height property,
which controls the height of a component. |
private void |
setSouth(Spring south)
|
void |
setWidth(Spring width)
Sets the width property,
which controls the width of a component. |
void |
setX(Spring x)
Sets the x property,
which controls the x value
of a component's location. |
void |
setY(Spring y)
Sets the y property,
which controls the y value
of a component's location. |
private Spring |
sum(Spring s1,
Spring s2)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private Spring x
private Spring y
private Spring width
private Spring height
private Spring east
private Spring south
private Spring verticalDerived
private Spring horizontalDerived
| Constructor Detail |
public SpringLayout.Constraints()
Constraints object.
public SpringLayout.Constraints(Spring x,
Spring y)
Constraints object with the
specified values for its
x and y properties.
The height and width springs
have null values.
x - the spring controlling the component's x valuey - the spring controlling the component's y value
public SpringLayout.Constraints(Spring x,
Spring y,
Spring width,
Spring height)
Constraints object with the
specified values for its
x, y, width,
and height properties.
Note: If the SpringLayout class
encounters null values in the
Constraints object of a given component,
it replaces them with suitable defaults.
x - the spring value for the x propertyy - the spring value for the y propertywidth - the spring value for the width propertyheight - the spring value for the height property| Method Detail |
private boolean overConstrainedHorizontally()
private boolean overConstrainedVertically()
private Spring sum(Spring s1,
Spring s2)
private Spring difference(Spring s1,
Spring s2)
public void setX(Spring x)
x property,
which controls the x value
of a component's location.
x - the spring controlling the x value
of a component's locationgetX(),
SpringLayout.Constraintspublic Spring getX()
x property.
x value
of a component's locationsetX(javax.swing.Spring),
SpringLayout.Constraintspublic void setY(Spring y)
y property,
which controls the y value
of a component's location.
y - the spring controlling the y value
of a component's locationgetY(),
SpringLayout.Constraintspublic Spring getY()
y property.
y value
of a component's locationsetY(javax.swing.Spring),
SpringLayout.Constraintspublic void setWidth(Spring width)
width property,
which controls the width of a component.
width - the spring controlling the width of this
Constraints objectgetWidth(),
SpringLayout.Constraintspublic Spring getWidth()
width property.
setWidth(javax.swing.Spring),
SpringLayout.Constraintspublic void setHeight(Spring height)
height property,
which controls the height of a component.
height - the spring controlling the height of this Constraints
objectgetHeight(),
SpringLayout.Constraintspublic Spring getHeight()
height property.
setHeight(javax.swing.Spring),
SpringLayout.Constraintsprivate void setEast(Spring east)
private Spring getEast()
private void setSouth(Spring south)
private Spring getSouth()
public void setConstraint(String edgeName,
Spring s)
SpringLayout.NORTH, SpringLayout.SOUTH,
SpringLayout.EAST, SpringLayout.WEST.
edgeName - the edge to be sets - the spring controlling the specified edgegetConstraint(java.lang.String),
SpringLayout.NORTH,
SpringLayout.SOUTH,
SpringLayout.EAST,
SpringLayout.WEST,
SpringLayout.Constraintspublic Spring getConstraint(String edgeName)
SpringLayout.NORTH, SpringLayout.SOUTH,
SpringLayout.EAST, SpringLayout.WEST.
edgeName - the edge whose value
is to be returned
setConstraint(java.lang.String, javax.swing.Spring),
SpringLayout.NORTH,
SpringLayout.SOUTH,
SpringLayout.EAST,
SpringLayout.WEST,
SpringLayout.Constraintsvoid reset()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||