2011-05-31 36 views
0

我正在使用Java Swing Synth外觀和感覺。我可以指定幾個組件的樣式。儘管如此,我無法爲默認狀態設置按鈕的字體顏色。按鈕文本始終以黑色顯示,但當對焦/選擇/移動鼠標時,文本顏色會變爲白色,然後變爲黑色。 這裏是我的合成器的XML文件的一個片段:使用XML和Java Swing合成器設置按鈕的字體顏色LaF

<synth> 
<style id="defaultStyle"> 
    <font name="Dialog" size="16" /> 
</style> 
<bind style="defaultStyle" type="region" key=".*" /> 
<style id="button"> 
    <property key="Button.textShiftOffset" type="integer" value="1"/> 
    <state> 
     <imagePainter method="buttonBackground" path="./images/JButton/default.png" 
      sourceInsets="20 24 20 24" paintCenter="true" stretch="true"/> 
     <insets top="20" left="24" bottom="20" right="24"/> 
     <color type="TEXT_FOREGROUND" value="#FFFFFF"/> 
    </state> 
</style> 
<bind style="button" type="region" key="Button" /> 
... 
</synth> 

難道我做錯了什麼?我怎樣才能改變按鈕的默認字體顏色?

一些額外的信息:

  • 的Java 1.6
  • Windows 7中,32位

回答

1

似乎我設法解決它。因爲沒有已知的原因,我不得不使用顏色tye「FOREGROUND」。

+0

謝謝,javadoc沒有指定'FOREGROUND'實際上是Button的文本顏色。 – afk5min 2013-08-16 04:04:14

0

試試你這個代替

<style id="button"> 
    <property key="Button.textShiftOffset" type="integer" value="1"/> 
    <font name="Dialog" size="12"/> 
    <state> 
     <imagePainter method="buttonBackground" path="./images/JButton/default.png" 
      sourceInsets="20 24 20 24" paintCenter="true" stretch="true"/> 
     <insets top="20" left="24" bottom="20" right="24"/> 
     <color type="TEXT_FOREGROUND" value="#FFFFFF"/> 
    </state> 
</style> 
<bind style="button" type="region" key="Button" /> 

link威力非常有用。