javax.swing
Class SpringLayout.Constraints

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.swing.SpringLayout.Constraints
Enclosing class:
SpringLayout sample code for javax.swing.SpringLayout definition code for javax.swing.SpringLayout

public static class SpringLayout.Constraints
extends Object sample code for java.lang.Object definition code for java.lang.Object

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 sample code for javax.swing.Spring definition code for javax.swing.Spring 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.


Constructor Summary
SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints() definition code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints() ()
          Creates an empty Constraints object.
SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints(java.awt.Component) definition code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints(java.awt.Component) (Component sample code for java.awt.Component definition code for java.awt.Component  c)
          Creates a Constraints object with suitable x, y, width and height springs for component, c.
SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring) (Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  x, Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  y)
          Creates a Constraints object with the specified values for its x and y properties.
SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring, javax.swing.Spring, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring, javax.swing.Spring, javax.swing.Spring) (Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  x, Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  y, Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  width, Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  height)
          Creates a Constraints object with the specified values for its x, y, width, and height properties.
 
Method Summary
 Spring sample code for javax.swing.Spring definition code for javax.swing.Spring getConstraint sample code for javax.swing.SpringLayout.Constraints.getConstraint(java.lang.String) definition code for javax.swing.SpringLayout.Constraints.getConstraint(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  edgeName)
          Returns the value of the specified edge.
 Spring sample code for javax.swing.Spring definition code for javax.swing.Spring getHeight sample code for javax.swing.SpringLayout.Constraints.getHeight() definition code for javax.swing.SpringLayout.Constraints.getHeight() ()
          Returns the value of the height property.
 Spring sample code for javax.swing.Spring definition code for javax.swing.Spring getWidth sample code for javax.swing.SpringLayout.Constraints.getWidth() definition code for javax.swing.SpringLayout.Constraints.getWidth() ()
          Returns the value of the width property.
 Spring sample code for javax.swing.Spring definition code for javax.swing.Spring getX sample code for javax.swing.SpringLayout.Constraints.getX() definition code for javax.swing.SpringLayout.Constraints.getX() ()
          Returns the value of the x property.
 Spring sample code for javax.swing.Spring definition code for javax.swing.Spring getY sample code for javax.swing.SpringLayout.Constraints.getY() definition code for javax.swing.SpringLayout.Constraints.getY() ()
          Returns the value of the y property.
 void setConstraint sample code for javax.swing.SpringLayout.Constraints.setConstraint(java.lang.String, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setConstraint(java.lang.String, javax.swing.Spring) (String sample code for java.lang.String definition code for java.lang.String  edgeName, Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  s)
          Sets the spring controlling the specified edge.
 void setHeight sample code for javax.swing.SpringLayout.Constraints.setHeight(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setHeight(javax.swing.Spring) (Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  height)
          Sets the height property, which controls the height of a component.
 void setWidth sample code for javax.swing.SpringLayout.Constraints.setWidth(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setWidth(javax.swing.Spring) (Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  width)
          Sets the width property, which controls the width of a component.
 void setX sample code for javax.swing.SpringLayout.Constraints.setX(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setX(javax.swing.Spring) (Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  x)
          Sets the x property, which controls the x value of a component's location.
 void setY sample code for javax.swing.SpringLayout.Constraints.setY(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setY(javax.swing.Spring) (Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  y)
          Sets the y property, which controls the y value of a component's location.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints() definition code for javax.swing.SpringLayout.Constraints()

public SpringLayout.Constraints()
Creates an empty Constraints object.


SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring)

public SpringLayout.Constraints(Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  x,
                                Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  y)
Creates a Constraints object with the specified values for its x and y properties. The height and width springs have null values.

Parameters:
x - the spring controlling the component's x value
y - the spring controlling the component's y value

SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring, javax.swing.Spring, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints(javax.swing.Spring, javax.swing.Spring, javax.swing.Spring, javax.swing.Spring)

public SpringLayout.Constraints(Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  x,
                                Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  y,
                                Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  width,
                                Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  height)
Creates a 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.

Parameters:
x - the spring value for the x property
y - the spring value for the y property
width - the spring value for the width property
height - the spring value for the height property

SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints(java.awt.Component) definition code for javax.swing.SpringLayout.Constraints(java.awt.Component)

public SpringLayout.Constraints(Component sample code for java.awt.Component definition code for java.awt.Component  c)
Creates a Constraints object with suitable x, y, width and height springs for component, c. The x and y springs are constant springs initialised with the component's location at the time this method is called. The width and height springs are special springs, created by the Spring.width() and Spring.height() methods, which track the size characteristics of the component when they change.

Parameters:
c - the component whose characteristics will be reflected by this Constraints object
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if c is null.
Since:
1.5
Method Detail

setX sample code for javax.swing.SpringLayout.Constraints.setX(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setX(javax.swing.Spring)

public void setX(Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  x)
Sets the x property, which controls the x value of a component's location.

Parameters:
x - the spring controlling the x value of a component's location
See Also:
getX() sample code for javax.swing.SpringLayout.Constraints.getX() definition code for javax.swing.SpringLayout.Constraints.getX() , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

getX sample code for javax.swing.SpringLayout.Constraints.getX() definition code for javax.swing.SpringLayout.Constraints.getX()

public Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  getX()
Returns the value of the x property.

Returns:
the spring controlling the x value of a component's location
See Also:
setX(javax.swing.Spring) sample code for javax.swing.SpringLayout.Constraints.setX(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setX(javax.swing.Spring) , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

setY sample code for javax.swing.SpringLayout.Constraints.setY(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setY(javax.swing.Spring)

public void setY(Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  y)
Sets the y property, which controls the y value of a component's location.

Parameters:
y - the spring controlling the y value of a component's location
See Also:
getY() sample code for javax.swing.SpringLayout.Constraints.getY() definition code for javax.swing.SpringLayout.Constraints.getY() , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

getY sample code for javax.swing.SpringLayout.Constraints.getY() definition code for javax.swing.SpringLayout.Constraints.getY()

public Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  getY()
Returns the value of the y property.

Returns:
the spring controlling the y value of a component's location
See Also:
setY(javax.swing.Spring) sample code for javax.swing.SpringLayout.Constraints.setY(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setY(javax.swing.Spring) , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

setWidth sample code for javax.swing.SpringLayout.Constraints.setWidth(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setWidth(javax.swing.Spring)

public void setWidth(Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  width)
Sets the width property, which controls the width of a component.

Parameters:
width - the spring controlling the width of this Constraints object
See Also:
getWidth() sample code for javax.swing.SpringLayout.Constraints.getWidth() definition code for javax.swing.SpringLayout.Constraints.getWidth() , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

getWidth sample code for javax.swing.SpringLayout.Constraints.getWidth() definition code for javax.swing.SpringLayout.Constraints.getWidth()

public Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  getWidth()
Returns the value of the width property.

Returns:
the spring controlling the width of a component
See Also:
setWidth(javax.swing.Spring) sample code for javax.swing.SpringLayout.Constraints.setWidth(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setWidth(javax.swing.Spring) , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

setHeight sample code for javax.swing.SpringLayout.Constraints.setHeight(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setHeight(javax.swing.Spring)

public void setHeight(Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  height)
Sets the height property, which controls the height of a component.

Parameters:
height - the spring controlling the height of this Constraints object
See Also:
getHeight() sample code for javax.swing.SpringLayout.Constraints.getHeight() definition code for javax.swing.SpringLayout.Constraints.getHeight() , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

getHeight sample code for javax.swing.SpringLayout.Constraints.getHeight() definition code for javax.swing.SpringLayout.Constraints.getHeight()

public Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  getHeight()
Returns the value of the height property.

Returns:
the spring controlling the height of a component
See Also:
setHeight(javax.swing.Spring) sample code for javax.swing.SpringLayout.Constraints.setHeight(javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setHeight(javax.swing.Spring) , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

setConstraint sample code for javax.swing.SpringLayout.Constraints.setConstraint(java.lang.String, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setConstraint(java.lang.String, javax.swing.Spring)

public void setConstraint(String sample code for java.lang.String definition code for java.lang.String  edgeName,
                          Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  s)
Sets the spring controlling the specified edge. The edge must have one of the following values: SpringLayout.NORTH, SpringLayout.SOUTH, SpringLayout.EAST, SpringLayout.WEST.

Parameters:
edgeName - the edge to be set
s - the spring controlling the specified edge
See Also:
getConstraint(java.lang.String) sample code for javax.swing.SpringLayout.Constraints.getConstraint(java.lang.String) definition code for javax.swing.SpringLayout.Constraints.getConstraint(java.lang.String) , SpringLayout.NORTH sample code for javax.swing.SpringLayout.NORTH definition code for javax.swing.SpringLayout.NORTH , SpringLayout.SOUTH sample code for javax.swing.SpringLayout.SOUTH definition code for javax.swing.SpringLayout.SOUTH , SpringLayout.EAST sample code for javax.swing.SpringLayout.EAST definition code for javax.swing.SpringLayout.EAST , SpringLayout.WEST sample code for javax.swing.SpringLayout.WEST definition code for javax.swing.SpringLayout.WEST , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints

getConstraint sample code for javax.swing.SpringLayout.Constraints.getConstraint(java.lang.String) definition code for javax.swing.SpringLayout.Constraints.getConstraint(java.lang.String)

public Spring sample code for javax.swing.Spring definition code for javax.swing.Spring  getConstraint(String sample code for java.lang.String definition code for java.lang.String  edgeName)
Returns the value of the specified edge. The edge must have one of the following values: SpringLayout.NORTH, SpringLayout.SOUTH, SpringLayout.EAST, SpringLayout.WEST.

Parameters:
edgeName - the edge whose value is to be returned
Returns:
the spring controlling the specified edge
See Also:
setConstraint(java.lang.String, javax.swing.Spring) sample code for javax.swing.SpringLayout.Constraints.setConstraint(java.lang.String, javax.swing.Spring) definition code for javax.swing.SpringLayout.Constraints.setConstraint(java.lang.String, javax.swing.Spring) , SpringLayout.NORTH sample code for javax.swing.SpringLayout.NORTH definition code for javax.swing.SpringLayout.NORTH , SpringLayout.SOUTH sample code for javax.swing.SpringLayout.SOUTH definition code for javax.swing.SpringLayout.SOUTH , SpringLayout.EAST sample code for javax.swing.SpringLayout.EAST definition code for javax.swing.SpringLayout.EAST , SpringLayout.WEST sample code for javax.swing.SpringLayout.WEST definition code for javax.swing.SpringLayout.WEST , SpringLayout.Constraints sample code for javax.swing.SpringLayout.Constraints definition code for javax.swing.SpringLayout.Constraints