- java.lang.Object
-
- javax.swing.SpringLayout.Constraints
-
- Enclosing class:
- SpringLayout
public static class SpringLayout.Constraints extends Object
AConstraintsobject holds the constraints that govern the way a component's size and position change in a container controlled by aSpringLayout. AConstraintsobject is like aRectangle, in that it hasx,y,width, andheightproperties. In theConstraintsobject, however, these properties haveSpringvalues instead of integers. In addition, aConstraintsobject can be manipulated as four edges -- north, south, east, and west -- using theconstraintproperty.The following formulas are always true for a
Constraintsobject (here WEST andxare synonyms, as are and NORTH andy):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) constuctor is called or when a constraints object is registered with a SpringLayout object.]
Note: In this document, operators represent methods in the
Springclass. For example, "a + b" is equal toSpring.sum(a, b), and "a - b" is equal toSpring.sum(a, Spring.minus(b)). See thefor further details of spring arithmetic.SpringAPI documentationBecause a
Constraintsobject's properties -- representing its edges, size, and location -- can all be set independently and yet are interrelated, aConstraintsobject can become over-constrained. For example, if theWEST,WIDTHandEASTedges are all set, steps must be taken to ensure that the first of the formulas above holds. To do this, theConstraintsobject throws away the least recently set constraint so as to make the formulas hold.- Since:
- 1.4
-
-
Constructor Summary
Constructors Constructor and Description SpringLayout.Constraints()Creates an emptyConstraintsobject.SpringLayout.Constraints(Component c)Creates aConstraintsobject with suitablex,y,widthandheightsprings for component,c.SpringLayout.Constraints(Spring x, Spring y)Creates aConstraintsobject with the specified values for itsxandyproperties.SpringLayout.Constraints(Spring x, Spring y, Spring width, Spring height)Creates aConstraintsobject with the specified values for itsx,y,width, andheightproperties.
-
Method Summary
Methods Modifier and Type Method and Description SpringgetConstraint(String edgeName)Returns the value of the specified edge, which may be a derived value, or evennull.SpringgetHeight()Returns the value of theheightproperty.SpringgetWidth()Returns the value of thewidthproperty.SpringgetX()Returns the value of thexproperty.SpringgetY()Returns the value of theyproperty.voidsetConstraint(String edgeName, Spring s)Sets the spring controlling the specified edge.voidsetHeight(Spring height)Sets theheightproperty, which controls the height of a component.voidsetWidth(Spring width)Sets thewidthproperty, which controls the width of a component.voidsetX(Spring x)Sets thexproperty, which controls thexvalue of a component's location.voidsetY(Spring y)Sets theyproperty, which controls theyvalue of a component's location.
-
-
-
Constructor Detail
-
SpringLayout.Constraints
public SpringLayout.Constraints()
Creates an emptyConstraintsobject.
-
SpringLayout.Constraints
public SpringLayout.Constraints(Spring x, Spring y)
Creates aConstraintsobject with the specified values for itsxandyproperties. Theheightandwidthsprings havenullvalues.- Parameters:
x- the spring controlling the component's x valuey- the spring controlling the component's y value
-
SpringLayout.Constraints
public SpringLayout.Constraints(Spring x, Spring y, Spring width, Spring height)
Creates 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 thexpropertyy- the spring value for theypropertywidth- the spring value for thewidthpropertyheight- the spring value for theheightproperty
-
SpringLayout.Constraints
public SpringLayout.Constraints(Component c)
Creates 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- ifcis null.- Since:
- 1.5
-
-
Method Detail
-
setX
public void setX(Spring x)
Sets thexproperty, which controls thexvalue of a component's location.- Parameters:
x- the spring controlling thexvalue of a component's location- See Also:
getX(),SpringLayout.Constraints
-
getX
public Spring getX()
Returns the value of thexproperty.- Returns:
- the spring controlling the
xvalue of a component's location - See Also:
setX(javax.swing.Spring),SpringLayout.Constraints
-
setY
public void setY(Spring y)
Sets theyproperty, which controls theyvalue of a component's location.- Parameters:
y- the spring controlling theyvalue of a component's location- See Also:
getY(),SpringLayout.Constraints
-
getY
public Spring getY()
Returns the value of theyproperty.- Returns:
- the spring controlling the
yvalue of a component's location - See Also:
setY(javax.swing.Spring),SpringLayout.Constraints
-
setWidth
public void setWidth(Spring width)
Sets thewidthproperty, which controls the width of a component.- Parameters:
width- the spring controlling the width of thisConstraintsobject- See Also:
getWidth(),SpringLayout.Constraints
-
getWidth
public Spring getWidth()
Returns the value of thewidthproperty.- Returns:
- the spring controlling the width of a component
- See Also:
setWidth(javax.swing.Spring),SpringLayout.Constraints
-
setHeight
public void setHeight(Spring height)
Sets theheightproperty, which controls the height of a component.- Parameters:
height- the spring controlling the height of thisConstraintsobject- See Also:
getHeight(),SpringLayout.Constraints
-
getHeight
public Spring getHeight()
Returns the value of theheightproperty.- Returns:
- the spring controlling the height of a component
- See Also:
setHeight(javax.swing.Spring),SpringLayout.Constraints
-
setConstraint
public void setConstraint(String edgeName, 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,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 affectxandyvalues previously set for thisConstraints.- Parameters:
edgeName- the edge to be sets- the spring controlling the specified edge- Throws:
NullPointerException- ifedgeNameisnull- See Also:
getConstraint(java.lang.String),SpringLayout.NORTH,SpringLayout.SOUTH,SpringLayout.EAST,SpringLayout.WEST,SpringLayout.HORIZONTAL_CENTER,SpringLayout.VERTICAL_CENTER,SpringLayout.BASELINE,SpringLayout.WIDTH,SpringLayout.HEIGHT,SpringLayout.Constraints
-
getConstraint
public Spring getConstraint(String edgeName)
Returns 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- ifedgeNameisnull- See Also:
setConstraint(java.lang.String, javax.swing.Spring),SpringLayout.NORTH,SpringLayout.SOUTH,SpringLayout.EAST,SpringLayout.WEST,SpringLayout.HORIZONTAL_CENTER,SpringLayout.VERTICAL_CENTER,SpringLayout.BASELINE,SpringLayout.WIDTH,SpringLayout.HEIGHT,SpringLayout.Constraints
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
09/10/2025 07:38:11 Cette version de la page est en cache (à la date du 09/10/2025 07:38:11) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/SpringLayout.Constraints.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.