|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 枚举常量 | 字段 | 方法 | 详细信息: 枚举常量 | 字段 | 方法 | |||||||||
java.lang.Objectjava.lang.Enum<Component.BaselineResizeBehavior>
java.awt.Component.BaselineResizeBehavior
public static enum Component.BaselineResizeBehavior
常见方式的枚举,指示组件的基线可以随大小的更改而更改。基线调整行为主要用于布局管理器,在组件大小发生更改时,布局管理器需要知道基线位置的更改方式。通常,在组件大小大于等于最小大小(实际最小大小;不是开发人员指定的最小大小)时,基线调整行为才是有效的。在组件大小小于最小大小的情况下,基线可能以基线调整行为所指示方式之外的某种方式发生更改。类似地,如果大小接近 Integer.MAX_VALUE 和/或 Short.MAX_VALUE,基线可能以基线调整行为所指示方式之外的某种方式发生更改。
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 |
| 枚举常量详细信息 |
|---|
public static final Component.BaselineResizeBehavior CONSTANT_ASCENT
getBaseline 均返回相同的值。例如,包含使用 TOP 垂直对齐方式的非空文本的 JLabel 应该具有 CONSTANT_ASCENT 基线类型。
public static final Component.BaselineResizeBehavior CONSTANT_DESCENT
getBaseline(w, H) 之间的差值是相同的。例如,包含使用 BOTTOM 垂直对齐方式的非空文本的 JLabel 应该具有 CONSTANT_DESCENT 基线类型。
public static final Component.BaselineResizeBehavior CENTER_OFFSET
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;
public static final Component.BaselineResizeBehavior OTHER
| 方法详细信息 |
|---|
public static final Component.BaselineResizeBehavior[] values()
for(Component.BaselineResizeBehavior c : Component.BaselineResizeBehavior.values())
System.out.println(c);
public static Component.BaselineResizeBehavior valueOf(String name)
指定要返回的枚举常量的名称。 -
如果该枚举类型没有带有指定名称的常量, - 则抛出 IllegalArgumentException
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 枚举常量 | 字段 | 方法 | 详细信息: 枚举常量 | 字段 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。