- Enclosing class:
- SpringLayout
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):
 
               EAST = WEST + WIDTH
              SOUTH = NORTH + HEIGHT
  HORIZONTAL_CENTER = WEST + WIDTH/2
    VERTICAL_CENTER = NORTH + HEIGHT/2
  ABSOLUTE_BASELINE = NORTH + RELATIVE_BASELINE*
 
 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.
[RELATIVE_BASELINE is a private constraint that is set automatically when the SpringLayout.Constraints(Component) constructor is called or when a constraints object is registered with a SpringLayout object.]
 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.
- Since:
- 1.4
- 
Constructor SummaryConstructorsConstructorDescriptionCreates an emptyConstraintsobject.Creates aConstraintsobject with suitablex,y,widthandheightsprings for component,c.Constraints(Spring x, Spring y) Creates aConstraintsobject with the specified values for itsxandyproperties.Constraints(Spring x, Spring y, Spring width, Spring height) Creates aConstraintsobject with the specified values for itsx,y,width, andheightproperties.
- 
Method SummaryModifier and TypeMethodDescriptiongetConstraint(String edgeName) Returns the value of the specified edge, which may be a derived value, or evennull.Returns the value of theheightproperty.getWidth()Returns the value of thewidthproperty.getX()Returns the value of thexproperty.getY()Returns the value of theyproperty.voidsetConstraint(String edgeName, Spring s) Sets the spring controlling the specified edge.voidSets theheightproperty, which controls the height of a component.voidSets thewidthproperty, which controls the width of a component.voidSets thexproperty, which controls thexvalue of a component's location.voidSets theyproperty, which controls theyvalue of a component's location.
- 
Constructor Details- 
Constraintspublic Constraints()Creates an emptyConstraintsobject.
- 
ConstraintsCreates aConstraintsobject with the specified values for itsxandyproperties. Theheightandwidthsprings havenullvalues.- Parameters:
- x- the spring controlling the component's x value
- y- the spring controlling the component's y value
 
- 
ConstraintsCreates aConstraintsobject with the specified values for itsx,y,width, andheightproperties. Note: If theSpringLayoutclass encountersnullvalues in theConstraintsobject of a given component, it replaces them with suitable defaults.- Parameters:
- x- the spring value for the- xproperty
- y- the spring value for the- yproperty
- width- the spring value for the- widthproperty
- height- the spring value for the- heightproperty
 
- 
ConstraintsCreates aConstraintsobject with suitablex,y,widthandheightsprings for component,c. Thexandysprings are constant springs initialised with the component's location at the time this method is called. Thewidthandheightsprings are special springs, created by theSpring.width()andSpring.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- if- cis null.
- Since:
- 1.5
 
 
- 
- 
Method Details- 
setXSets thexproperty, which controls thexvalue of a component's location.- Parameters:
- x- the spring controlling the- xvalue of a component's location
- See Also:
 
- 
getXReturns the value of thexproperty.- Returns:
- the spring controlling the xvalue of a component's location
- See Also:
 
- 
setYSets theyproperty, which controls theyvalue of a component's location.- Parameters:
- y- the spring controlling the- yvalue of a component's location
- See Also:
 
- 
getYReturns the value of theyproperty.- Returns:
- the spring controlling the yvalue of a component's location
- See Also:
 
- 
setWidthSets thewidthproperty, which controls the width of a component.- Parameters:
- width- the spring controlling the width of this- Constraintsobject
- See Also:
 
- 
getWidthReturns the value of thewidthproperty.- Returns:
- the spring controlling the width of a component
- See Also:
 
- 
setHeightSets theheightproperty, which controls the height of a component.- Parameters:
- height- the spring controlling the height of this- Constraintsobject
- See Also:
 
- 
getHeightReturns the value of theheightproperty.- Returns:
- the spring controlling the height of a component
- See Also:
 
- 
setConstraintSets the spring controlling the specified edge. 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.WIDTHorSpringLayout.HEIGHT. For any otherStringvalue passed as the edge, no action is taken. For anulledge, aNullPointerExceptionis thrown.Note: This method can affect xandyvalues previously set for thisConstraints.- Parameters:
- edgeName- the edge to be set
- s- the spring controlling the specified edge
- Throws:
- NullPointerException- if- edgeNameis- null
- See Also:
 
- 
getConstraintReturns the value of the specified edge, which may be a derived value, or evennull. 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.WIDTHorSpringLayout.HEIGHT. For any otherStringvalue passed as the edge,nullwill be returned. ThrowsNullPointerExceptionfor anulledge.- Parameters:
- edgeName- the edge whose value is to be returned
- Returns:
- the spring controlling the specified edge, may be null
- Throws:
- NullPointerException- if- edgeNameis- null
- See Also:
 
 
-