JavaTM 2 Platform
Standard Ed. 6

javax.swing.plaf.synth
類別 ColorType

java.lang.Object
  繼承者 javax.swing.plaf.synth.ColorType

public class ColorType
extends Object

可從某種樣式中獲取的一些顏色的型別安全列舉。

每個 SynthStyle 都有一組 ColorType,可以使用 SynthStyle.getColor(SynthContext, ColorType) 方法來存取它們。SynthStyleinstallDefaults 將安裝 FOREGROUND 顏色作為 Component 的前景色,並安裝 BACKGROUND 顏色作為元件的背景色(假定您沒有顯式指定前景色和背景色)。一些元件支持更多基於顏色的屬性,例如,JList 擁有屬性 selectionForeground,該屬性將在元件狀態為 SynthConstants.SELECTED 的情況下被映射到 FOREGROUND

以下範例顯示了一個自定義 SynthStyle,對於 DISABLED 狀態,它返回紅色,其他情況返回黑色。

 class MyStyle extends SynthStyle {
     private Color disabledColor = new ColorUIResource(Color.RED);
     private Color color = new ColorUIResource(Color.BLACK);
     protected Color getColorForState(SynthContext context, ColorType type){
         if (context.getComponentState() == SynthConstants.DISABLED) {
             return disabledColor;
         }
         return color;
     }
 }
 

從以下版本開始:
1.5

欄位摘要
static ColorType BACKGROUND
          某一 region 背景的 ColorType。
static ColorType FOCUS
          焦點的 ColorType。
static ColorType FOREGROUND
          某一 region 前景的 ColorType。
static int MAX_COUNT
          最大 ColorType 數。
static ColorType TEXT_BACKGROUND
          某一 region 背景的 ColorType。
static ColorType TEXT_FOREGROUND
          某一 region 前景的 ColorType。
 
建構子摘要
protected ColorType(String description)
          創建一個具有指定描述的 ColorType。
 
方法摘要
 int getID()
          以整數形式返回此 ColorType 的唯一 id。
 String toString()
          返回此 ColorType 的文本描述。
 
從類別 java.lang.Object 繼承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

欄位詳細資訊

FOREGROUND

public static final ColorType FOREGROUND
某一 region 前景的 ColorType。


BACKGROUND

public static final ColorType BACKGROUND
某一 region 背景的 ColorType。


TEXT_FOREGROUND

public static final ColorType TEXT_FOREGROUND
某一 region 前景的 ColorType。


TEXT_BACKGROUND

public static final ColorType TEXT_BACKGROUND
某一 region 背景的 ColorType。


FOCUS

public static final ColorType FOCUS
焦點的 ColorType。


MAX_COUNT

public static final int MAX_COUNT
最大 ColorType 數。

建構子詳細資訊

ColorType

protected ColorType(String description)
創建一個具有指定描述的 ColorType。

參數:
description - ColorType 的字元串描述。
方法詳細資訊

getID

public final int getID()
以整數形式返回此 ColorType 的唯一 id。

返回:
以整數形式返回此 ColorType 的唯一 id。

toString

public String toString()
返回此 ColorType 的文本描述。 返回值就是用來創建 ColorType 的那個值。

覆寫:
類別 Object 中的 toString
返回:
字元串的描述。

JavaTM 2 Platform
Standard Ed. 6

提交錯誤或意見

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