【问题标题】:setting font color of button using XML and Java Swing Synth LaF使用 XML 和 Java Swing Synth LaF 设置按钮的字体颜色
【发布时间】:2011-09-05 14:02:38
【问题描述】:

我正在使用 Java Swing Synth 外观。我可以指定几个组件的样式。尽管如此,我无法将按钮的字体颜色设置为默认状态。按钮的文本始终以黑色显示,但是当聚焦/选择/将鼠标移到文本上时,颜色会变为白色,然后又变为黑色。 这是我的 synth-XML 文件的 sn-p:

<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 位

【问题讨论】:

    标签: java colors look-and-feel foreground synth


    【解决方案1】:

    看来我设法解决了它。不知为何,我不得不使用颜色“FOREGROUND”。

    【讨论】:

    • 谢谢,javadoc没有指定'FOREGROUND'实际上是Button的文本颜色。
    【解决方案2】:

    试试这个

    <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 可能对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-08
      • 2023-03-11
      • 1970-01-01
      • 2011-03-26
      • 2020-04-25
      • 1970-01-01
      • 2013-08-30
      • 2014-05-07
      相关资源
      最近更新 更多