JavaTM 2 Platform
Standard Ed. 5.0

javax.swing
类 SpringLayout.Constraints

java.lang.Object
  继承者 javax.swing.SpringLayout.Constraints
正在封闭类:
SpringLayout

public static class SpringLayout.Constraints
extends Object

Constraints 对象将管理组件大小和位置更改方式的约束存储在 SpringLayout 控制的容器中。由于 Constraints 对象具有 x、y、width 和 height 属性,因而它类似于一个 Rectangle。但是,在 Constraints 对象中,这些属性具有的是 Spring 值,而不是整数。此外,可以使用 constraint 属性按四个边(东、南、西、北)操作一个 Constraints 对象。

对于 Constraints 对象,以下公式始终为 true:

       west = x
      north = y
       east = x + width
      south = y + height
注:在本文档中,操作符表示该 Spring 类中的方法。例如,"a + b" 等于 Spring.sum(a, b),"a - b" 等于 Spring.sum(a, Spring.minus(b))。有关 spring 算法的更详细信息,请参阅 Spring API documentation。

因为 Constraints 对象的属性(表示其边、大小和位置)都可以单独设置,并且互相关联,所以该对象可以成为过分约束。例如,如果先设置 x 和 width 属性,然后设置东边,则该对象将在水平方向受过分约束。出现这种情况时,其中某个值(在此情况下,指 x 属性)将自动更改,以使公式仍起作用。

下表显示在 Constraints 对象受到水平方向的过分约束时发生更改的值。

正在设置的值
(使用的方法)
水平方向受过分约束时的结果
(x、width 和东边都为非 null)
x 或西边
(setX 或 setConstraint)
width 值将自动设置为 east - x。
width
(setWidth)
东边的值将自动设置为 x + width。
西边
(setConstraint)
x 值将自动设置为 east - width。

该垂直属性的规则类似于:

正在设置的值
(使用的方法)
垂直方向受过分约束的结果
(y、height 和南边都为非 null)
y 或北边
(setY 或 setConstraint)
height 值将自动设置为 south - y。
height
(setHeight)
南边的值将自动设置为 y + height。
南边
(setConstraint)
y 值将自动设置为 south - height。


构造方法摘要
SpringLayout.Constraints()
          创建一个空 Constraints 对象。
SpringLayout.Constraints(Component c)
          创建组件 c 的合适 x、y、width 和 height spring 的 Constraints 对象。
SpringLayout.Constraints(Spring x, Spring y)
          创建一个指定了 x 和 y 属性值的 Constraints 对象。
SpringLayout.Constraints(Spring x, Spring y, Spring width, Spring height)
          创建一个指定了 x、y、width 和 height 属性值的 Constraints 对象。
 
方法摘要
 Spring getConstraint(String edgeName)
          返回指定边的值。
 Spring getHeight()
          返回 height 属性的值。
 Spring getWidth()
          返回 width 属性的值。
 Spring getX()
          返回 x 属性的值。
 Spring getY()
          返回 y 属性的值。
 void setConstraint(String edgeName, Spring s)
          设置控制指定边的 spring。
 void setHeight(Spring height)
          设置 height 属性,该属性控制组件的高度。
 void setWidth(Spring width)
          设置 width 属性,该属性控制组件的宽度。
 void setX(Spring x)
          设置 x 属性,该属性控制组件位置的 x 值。
 void setY(Spring y)
          设置 y 属性,该属性控制组件位置的 y 值。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

SpringLayout.Constraints

public SpringLayout.Constraints()
创建一个空 Constraints 对象。


SpringLayout.Constraints

public SpringLayout.Constraints(Spring x,
                                Spring y)
创建一个指定了 x 和 y 属性值的 Constraints 对象。height 和 width spring 具有 null 值。

参数:
x - 控制组件的 x 值的 spring
y - 控制组件的 y 值的 spring

SpringLayout.Constraints

public SpringLayout.Constraints(Spring x,
                                Spring y,
                                Spring width,
                                Spring height)
创建一个指定了 x、y、width 和 height 属性值的 Constraints 对象。注:如果 SpringLayout 类在给定组件的 Constraints 对象中遇到 null 值,则它将使用合适的默认值取代这些值。

参数:
x - x 属性的 spring 值
y - y 属性的 spring 值
width - width 属性的 spring 值
height - height 属性的 spring 值

SpringLayout.Constraints

public SpringLayout.Constraints(Component c)
创建组件 c 的合适 x、y、width 和 height spring 的 Constraints 对象。x 和 y spring 是使用调用此方法时该组件的位置初始化的常量 spring。width 和 height spring 是由 Spring.width() 和 Spring.height() 方法创建的特殊 spring,这些方法可在组件的大小特征发生变化时进行跟踪。

参数:
c - 此约束对象反映其特征的组件
抛出:
NullPointerException - 如果 c 为 null。
从以下版本开始:
1.5
方法详细信息

setX

public void setX(Spring x)
设置 x 属性,该属性控制组件位置的 x 值。

参数:
x - 控制组件位置的 x 值的 spring
另请参见:
getX(), SpringLayout.Constraints

getX

public Spring getX()
返回 x 属性的值。

返回:
控制组件位置的 x 值的 spring
另请参见:
setX(javax.swing.Spring), SpringLayout.Constraints

setY

public void setY(Spring y)
设置 y 属性,该属性控制组件位置的 y 值。

参数:
y - 控制组件位置的 y 值的 spring
另请参见:
getY(), SpringLayout.Constraints

getY

public Spring getY()
返回 y 属性的值。

返回:
控制组件位置的 y 值的 spring
另请参见:
setY(javax.swing.Spring), SpringLayout.Constraints

setWidth

public void setWidth(Spring width)
设置 width 属性,该属性控制组件的宽度。

参数:
width - 控制此 Constraints 对象的宽度的 spring
另请参见:
getWidth(), SpringLayout.Constraints

getWidth

public Spring getWidth()
返回 width 属性的值。

返回:
控制组件宽度的 spring
另请参见:
setWidth(javax.swing.Spring), SpringLayout.Constraints

setHeight

public void setHeight(Spring height)
设置 height 属性,该属性控制组件的高度。

参数:
height - 控制此 Constraints 对象高度的 spring
另请参见:
getHeight(), SpringLayout.Constraints

getHeight

public Spring getHeight()
返回 height 属性的值。

返回:
控制组件高度的 spring
另请参见:
setHeight(javax.swing.Spring), SpringLayout.Constraints

setConstraint

public void setConstraint(String edgeName,
                          Spring s)
设置控制指定边的 spring。该边必须是以下某个值:SpringLayout.NORTH、SpringLayout.SOUTH、SpringLayout.EAST、SpringLayout.WEST。

参数:
edgeName - 要设置的边
s - 控制指定边的 spring
另请参见:
getConstraint(java.lang.String), SpringLayout.NORTH, SpringLayout.SOUTH, SpringLayout.EAST, SpringLayout.WEST, SpringLayout.Constraints

getConstraint

public Spring getConstraint(String edgeName)
返回指定边的值。该边必须是以下某个值:SpringLayout.NORTH、SpringLayout.SOUTH、SpringLayout.EAST、SpringLayout.WEST。

参数:
edgeName - 要返回其值的边
返回:
控制指定边的 spring
另请参见:
setConstraint(java.lang.String, javax.swing.Spring), SpringLayout.NORTH, SpringLayout.SOUTH, SpringLayout.EAST, SpringLayout.WEST, SpringLayout.Constraints

JavaTM 2 Platform
Standard Ed. 5.0

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。