2011-05-31 80 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威力非常有用。