- java.lang.Object
-
- javax.swing.SpringLayout.Constraints
-
- Enclosing class:
- SpringLayout
public static class SpringLayout.Constraints extends Object
AConstraints
object holds the constraints that govern the way a component's size and position change in a container controlled by aSpringLayout
. AConstraints
object is like aRectangle
, in that it hasx
,y
,width
, andheight
properties. In theConstraints
object, however, these properties haveSpring
values instead of integers. In addition, aConstraints
object can be manipulated as four edges -- north, south, east, and west -- using theconstraint
property.The following formulas are always true for a
Constraints
object (here WEST andx
are 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
Spring
class. For example, "a + b" is equal toSpring.sum(a, b)
, and "a - b" is equal toSpring.sum(a, Spring.minus(b))
. See the
for further details of spring arithmetic.Spring
API documentationBecause a
Constraints
object's properties -- representing its edges, size, and location -- can all be set independently and yet are interrelated, aConstraints
object can become over-constrained. For example, if theWEST
,WIDTH
andEAST
edges are all set, steps must be taken to ensure that the first of the formulas above holds. To do this, theConstraints
object 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 emptyConstraints
object.SpringLayout.Constraints(Component c)
Creates aConstraints
object with suitablex
,y
,width
andheight
springs for component,c
.SpringLayout.Constraints(Spring x, Spring y)
Creates aConstraints
object with the specified values for itsx
andy
properties.SpringLayout.Constraints(Spring x, Spring y, Spring width, Spring height)
Creates aConstraints
object with the specified values for itsx
,y
,width
, andheight
properties.
-
Method Summary
Methods Modifier and Type Method and Description Spring
getConstraint(String edgeName)
Returns the value of the specified edge, which may be a derived value, or evennull
.Spring
getHeight()
Returns the value of theheight
property.Spring
getWidth()
Returns the value of thewidth
property.Spring
getX()
Returns the value of thex
property.Spring
getY()
Returns the value of they
property.void
setConstraint(String edgeName, Spring s)
Sets the spring controlling the specified edge.void
setHeight(Spring height)
Sets theheight
property, which controls the height of a component.void
setWidth(Spring width)
Sets thewidth
property, which controls the width of a component.void
setX(Spring x)
Sets thex
property, which controls thex
value of a component's location.void
setY(Spring y)
Sets they
property, which controls they
value of a component's location.
-
-
-
Constructor Detail
-
SpringLayout.Constraints
public SpringLayout.Constraints()
Creates an emptyConstraints
object.
-
SpringLayout.Constraints
public SpringLayout.Constraints(Spring x, Spring y)
Creates aConstraints
object with the specified values for itsx
andy
properties. Theheight
andwidth
springs havenull
values.- 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 aConstraints
object with the specified values for itsx
,y
,width
, andheight
properties. Note: If theSpringLayout
class encountersnull
values in theConstraints
object of a given component, it replaces them with suitable defaults.- Parameters:
x
- the spring value for thex
propertyy
- the spring value for they
propertywidth
- the spring value for thewidth
propertyheight
- the spring value for theheight
property
-
SpringLayout.Constraints
public SpringLayout.Constraints(Component c)
Creates aConstraints
object with suitablex
,y
,width
andheight
springs for component,c
. Thex
andy
springs are constant springs initialised with the component's location at the time this method is called. Thewidth
andheight
springs 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
- ifc
is null.- Since:
- 1.5
-
-
Method Detail
-
setX
public void setX(Spring x)
Sets thex
property, which controls thex
value of a component's location.- Parameters:
x
- the spring controlling thex
value of a component's location- See Also:
getX()
,SpringLayout.Constraints
-
getX
public Spring getX()
Returns the value of thex
property.- Returns:
- the spring controlling the
x
value of a component's location - See Also:
setX(javax.swing.Spring)
,SpringLayout.Constraints
-
setY
public void setY(Spring y)
Sets they
property, which controls they
value of a component's location.- Parameters:
y
- the spring controlling they
value of a component's location- See Also:
getY()
,SpringLayout.Constraints
-
getY
public Spring getY()
Returns the value of they
property.- Returns:
- the spring controlling the
y
value of a component's location - See Also:
setY(javax.swing.Spring)
,SpringLayout.Constraints
-
setWidth
public void setWidth(Spring width)
Sets thewidth
property, which controls the width of a component.- Parameters:
width
- the spring controlling the width of thisConstraints
object- See Also:
getWidth()
,SpringLayout.Constraints
-
getWidth
public Spring getWidth()
Returns the value of thewidth
property.- Returns:
- the spring controlling the width of a component
- See Also:
setWidth(javax.swing.Spring)
,SpringLayout.Constraints
-
setHeight
public void setHeight(Spring height)
Sets theheight
property, which controls the height of a component.- Parameters:
height
- the spring controlling the height of thisConstraints
object- See Also:
getHeight()
,SpringLayout.Constraints
-
getHeight
public Spring getHeight()
Returns the value of theheight
property.- 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.WIDTH
orSpringLayout.HEIGHT
. For any otherString
value passed as the edge, no action is taken. For anull
edge, aNullPointerException
is thrown. Note: This method can affectx
andy
values previously set for thisConstraints
.- Parameters:
edgeName
- the edge to be sets
- the spring controlling the specified edge- Throws:
NullPointerException
- ifedgeName
isnull
- 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.WIDTH
orSpringLayout.HEIGHT
. For any otherString
value passed as the edge,null
will be returned. ThrowsNullPointerException
for anull
edge.- Parameters:
edgeName
- the edge whose value is to be returned- Returns:
- the spring controlling the specified edge, may be
null
- Throws:
NullPointerException
- ifedgeName
isnull
- 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
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/swing/SpringLayout.Constraints.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.