|
JavaTM 2 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 垂直對齊方式的非空(null)文本的 JLabel 應該具有 CONSTANT_ASCENT 基線型別。
public static final Component.BaselineResizeBehavior CONSTANT_DESCENT
getBaseline(w, H) 之間的差值是相同的。例如,包含使用 BOTTOM 垂直對齊方式的非空(null)文本的 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 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 列舉常數 | 欄位 | 方法 | 詳細資訊: 列舉常數 | 欄位 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。