JavaTM 2 Platform
Standard Ed. 6

java.awt
枚举 Component.BaselineResizeBehavior

java.lang.Object
  继承者 java.lang.Enum<Component.BaselineResizeBehavior>
      继承者 java.awt.Component.BaselineResizeBehavior
所有已实现的接口:
Serializable, Comparable<Component.BaselineResizeBehavior>
正在封闭类:
Component

public static enum Component.BaselineResizeBehavior
extends Enum<Component.BaselineResizeBehavior>

常见方式的枚举,指示组件的基线可以随大小的更改而更改。基线调整行为主要用于布局管理器,在组件大小发生更改时,布局管理器需要知道基线位置的更改方式。通常,在组件大小大于等于最小大小(实际最小大小;不是开发人员指定的最小大小)时,基线调整行为才是有效的。在组件大小小于最小大小的情况下,基线可能以基线调整行为所指示方式之外的某种方式发生更改。类似地,如果大小接近 Integer.MAX_VALUE 和/或 Short.MAX_VALUE,基线可能以基线调整行为所指示方式之外的某种方式发生更改。

从以下版本开始:
1.6
另请参见:
Component.getBaselineResizeBehavior(), Component.getBaseline(int,int)

枚举常量摘要
CENTER_OFFSET
          指示基线与组件的中心保持固定的距离。
CONSTANT_ASCENT
          指示基线相对于 y 原点保持不变。
CONSTANT_DESCENT
          指示基线相对于高度保持不变,且不会随着宽度不同而发生更改。
OTHER
          指示基线调整行为无法使用其他任何常量表示。
 
方法摘要
static Component.BaselineResizeBehavior valueOf(String name)
          返回带有指定名称的该类型的枚举常量。
static Component.BaselineResizeBehavior[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
从类 java.lang.Enum 继承的方法
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
从类 java.lang.Object 继承的方法
getClass, notify, notifyAll, wait, wait, wait
 

枚举常量详细信息

CONSTANT_ASCENT

public static final Component.BaselineResizeBehavior CONSTANT_ASCENT
指示基线相对于 y 原点保持不变。也就是说,无论高度或宽度如何,getBaseline 均返回相同的值。例如,包含使用 TOP 垂直对齐方式的非空文本的 JLabel 应该具有 CONSTANT_ASCENT 基线类型。


CONSTANT_DESCENT

public static final Component.BaselineResizeBehavior CONSTANT_DESCENT
指示基线相对于高度保持不变,且不会随着宽度不同而发生更改。也就是说,对于任意高度 H,H 和 getBaseline(w, H) 之间的差值是相同的。例如,包含使用 BOTTOM 垂直对齐方式的非空文本的 JLabel 应该具有 CONSTANT_DESCENT 基线类型。


CENTER_OFFSET

public static final Component.BaselineResizeBehavior CENTER_OFFSET
指示基线与组件的中心保持固定的距离。也就是说,对于任意高度 H,getBaseline(w, H)H / 2 之间的差值是相同的(根据舍入误差加上或减去 1)。

因为可能存在舍入误差,所以建议通过两个连续高度请求(计算)基线,并使用返回值来确定计算结果是否需要值为 1 的 pad。以下显示了如何计算任意高度的基线:

Dimension preferredSize = component.getPreferredSize();
int baseline = getBaseline(preferredSize.width,
preferredSize.height);
int nextBaseline = getBaseline(preferredSize.width,
preferredSize.height + 1);
// Amount to add to height when calculating where baseline
// lands for a particular height:
int padding = 0;
// Where the baseline is relative to the mid point
int baselineOffset = baseline - height / 2;
if (preferredSize.height % 2 == 0 &&
baseline != nextBaseline) {
padding = 1;
   }
else if (preferredSize.height % 2 == 1 &&
baseline == nextBaseline) {
baselineOffset--;
padding = 1;
   }
// The following calculates where the baseline lands for
// the height z:
int calculatedBaseline = (z + padding) / 2 + baselineOffset;
 


OTHER

public static final Component.BaselineResizeBehavior OTHER
指示基线调整行为无法使用其他任何常量表示。它也可能指示基线随组件宽度的不同而不同。没有基线的组件也会返回它。

方法详细信息

values

public static final Component.BaselineResizeBehavior[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for(Component.BaselineResizeBehavior c : Component.BaselineResizeBehavior.values())
        System.out.println(c);

返回:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Component.BaselineResizeBehavior valueOf(String name)
返回带有指定名称的该类型的枚举常量。 字符串必须与用于声明该类型的枚举常量的 标识符完全匹配。(不允许有多余 的空格。)

参数:
指定要返回的枚举常量的名称。 -
返回:
返回带有指定名称的枚举常量
抛出:
如果该枚举类型没有带有指定名称的常量, - 则抛出 IllegalArgumentException

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only