is new.
java.lang.Objectjavax.swing.SpringLayout.Constraints
public static class 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 (here WEST and x are synonyms, as are and NORTH and y):
object:
EAST = WEST + WIDTH SOUTH = NORTH + HEIGHT HORIZONTAL_CENTER = WEST + WIDTH/2 VERTICAL_CENTER = NORTH + HEIGHT/2 ABSOLUTE_BASELINE = NORTH + RELATIVE_BASELINE*
west = x north = y east = x + width south = y + height
For example, if you have specified the WIDTH and WEST (X) location the EAST is calculated as WEST + WIDTH. If you instead specified the WIDTH and EAST locations the WEST (X) location is then calculated as EAST - WIDTH.
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.
[RELATIVE_BASELINE is a private constraint that is set automatically when the SpringLayout.Constraints(Component) constuctor is called or when a constraints object is registered with a SpringLayout object.]
The following table shows which value changes when a Constraints object is over-constrained horizontally.
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, a Constraints object can become over-constrained. For example, if the WEST, WIDTH and EAST edges are all set, steps must be taken to ensure that the first of the formulas above holds. To do this, the Constraints object throws away the least recently set constraint so as to make the formulas hold.
The rules for the vertical properties are similar:
| Constructor Summary | |
|---|---|
|
SpringLayout.Constraints
() Creates an empty Constraints object. |
|
|
SpringLayout.Constraints
(
Component
c) Creates a Constraints object with suitable x, y, width and height springs for component, c. |
|
|
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 | |
|---|---|
| Spring |
getConstraint
(
String
Returns the value of the specified
edge, which may be a derived value, or even null.
|
| Spring |
getHeight
() Returns the value of the height property. |
| 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. |
| void |
setConstraint
(
String
edgeName,
Spring
s) Sets the spring controlling the specified edge. |
| void |
setHeight
(
Spring
height) Sets the height property, which controls the height of a component. |
| 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. |
| Methods inherited from class java.lang. Object |
|---|
| clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
| Constructor Detail |
|---|
public SpringLayout.Constraints()
public SpringLayout.Constraints(Spring x,
Spring y)
public SpringLayout.Constraints(Spring x,
Spring y,
Spring width,
Spring height)
public SpringLayout.Constraints(Component c)
| Method Detail |
|---|
public void setX(Spring x)
public Spring getX()
public void setY(Spring y)
public Spring getY()
public void setWidth(Spring width)
public Spring getWidth()
public void setHeight(Spring height)
public Spring getHeight()
public void setConstraint(String edgeName,
Spring s)
The edge must have one of the following values: SpringLayout.NORTH, SpringLayout.SOUTH, SpringLayout.EAST, SpringLayout.WEST, SpringLayout.HORIZONTAL_CENTER, SpringLayout.VERTICAL_CENTER, SpringLayout.BASELINE, SpringLayout.WIDTH or SpringLayout.HEIGHT. For any other String value passed as the edge, no action is taken. For a null edge, a NullPointerException is thrown.
Throws:
NullPointerException
- if edgeName is null
,
SpringLayout.HORIZONTAL_CENTER
,
SpringLayout.VERTICAL_CENTER
,
SpringLayout.BASELINE
,
SpringLayout.WIDTH
,
SpringLayout.HEIGHT
,
SpringLayout.Constraints
public Spring getConstraint(String edgeName)
Returns the value of the specified edge, which may be a derived value, or even null. The edge must have one of the following values: SpringLayout.NORTH, SpringLayout.SOUTH, SpringLayout.EAST, SpringLayout.WEST, SpringLayout.HORIZONTAL_CENTER, SpringLayout.VERTICAL_CENTER, SpringLayout.BASELINE, SpringLayout.WIDTH or SpringLayout.HEIGHT. For any other String value passed as the edge, null will be returned. Throws NullPointerException for a null edge.
edge, may be null
Throws:
NullPointerException
- if edgeName is null
,
SpringLayout.HORIZONTAL_CENTER
,
SpringLayout.VERTICAL_CENTER
,
SpringLayout.BASELINE
,
SpringLayout.WIDTH
,
SpringLayout.HEIGHT
,
SpringLayout.Constraints