JavaTM Platform
Standard Ed. 6

javax.swing
类 SpringLayout.Constraints

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

public static class SpringLayout.Constraints
     
extends Object

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

对于 Constraints 对象,以下公式始终为 true(这里 WEST 和 x 同义,同样地 NORTH 和 y 同义):

               EAST = WEST + WIDTH
              SOUTH = NORTH + HEIGHT
  HORIZONTAL_CENTER = WEST + WIDTH/2
    VERTICAL_CENTER = NORTH + HEIGHT/2
  ABSOLUTE_BASELINE = NORTH + RELATIVE_BASELINE*
 

例如,如果指定 WIDTH 和 WEST (X) 位置,则 EAST 按 WEST + WIDTH 计算。如果指定 WIDTH 和 EAST 位置,则 WEST (X) 位置按 EAST - WIDTH 计算。

[RELATIVE_BASELINE 是调用 SpringLayout.Constraints(Component) 时或向 SpringLayout 对象注册约束对象时自动设置的专有约束]。

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

因为 Constraints 对象的属性(表示其边、大小和位置)都可以单独设置,并且互相关联,所以 Constraints 对象可以成为过分约束。例如,如果设置了 WESTWIDTHEAST 边,则必须采取措施以确保上述公式中的第一个有效。要做到这一点,Constraints 对象抛出最近设置的 约束以使公式有效。

从以下版本开始:
1.4

构造方法摘要
SpringLayout.Constraints()
          创建一个空 Constraints 对象。
SpringLayout.Constraints(Component c)
          创建组件 c 的合适 xywidthheight spring 的 Constraints 对象。
SpringLayout.Constraints(Spring x, Spring y)
          创建一个指定了 xy 属性值的 Constraints 对象。
SpringLayout.Constraints(Spring x, Spring y, Spring width, Spring height)
          创建一个指定了 xywidthheight 属性值的 Constraints 对象。
 
方法摘要
 Spring getConstraint(String edgeName)
          返回指定边的值,它可以为一个派生值,甚至可以为 null
 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)
创建一个指定了 xy 属性值的 Constraints 对象。 heightwidth spring 具有 null 值。

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

SpringLayout.Constraints

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

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

SpringLayout.Constraints

public SpringLayout.Constraints(Component c)
创建组件 c 的合适 xywidthheight spring 的 Constraints 对象。 xy spring 是使用调用此方法时该组件的位置初始化的常量 spring。 widthheight 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.NORTHSpringLayout.SOUTHSpringLayout.EASTSpringLayout.WESTSpringLayout.HORIZONTAL_CENTERSpringLayout.VERTICAL_CENTERSpringLayout.BASELINESpringLayout.WIDTHSpringLayout.HEIGHT。 对于作为边传递的任何其他 String 值,则不执行任何操作。对于 null 边,则抛出 NullPointerException

参数:
edgeName - 要设置的边
s - 控制指定边的 spring
抛出:
NullPointerException - 如果 edgeNamenull
另请参见:
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)
返回指定边的值,它可以为一个派生值,甚至可以为 null。该边必须是以下某个值: SpringLayout.NORTHSpringLayout.SOUTHSpringLayout.EASTSpringLayout.WESTSpringLayout.HORIZONTAL_CENTERSpringLayout.VERTICAL_CENTERSpringLayout.BASELINESpringLayout.WIDTHSpringLayout.HEIGHT。 对于作为边传递的任何其他 String 值,则会返回 null。对于 null 边,则抛出 NullPointerException

参数:
edgeName - 要返回其值的边
返回:
控制指定边的 spring,可以为 null
抛出:
NullPointerException - 如果 edgeNamenull
另请参见:
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

JavaTM Platform
Standard Ed. 6

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

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