如何设置SWT按钮的前景色? [英] How to set SWT button foreground color?

查看:472
本文介绍了如何设置SWT按钮的前景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SWT Button类有一个 setForeground(Color)方法,但它似乎没有效果(该方法实际上是在Button的超类)。 javadoc说这个方法是一个提示,可能被平台覆盖。我的平台是Windows。




  • 这是否意味着不可能在Windows上设置按钮前景色?
  • $ b $

解决方案

在Windows上, setForeground 按钮作为解决方法,向按钮中添加 PaintListener 。在此侦听器的 paintControl 方法中,获取生成的事件的 GC ,并重写<



你可以在你的上绘制任何东西, Button


The SWT Button class has a setForeground(Color) method but it seems to have no effect (the method is actually on Button's superclass). The javadoc says that this method is a hint and may be overridden by the platform. My platform is Windows.

  • Does this mean that it is not possible to set button foreground color on Windows?
  • Does it work on other platforms?
  • Is there a workaround?

解决方案

On Windows, setForeground for Buttons has no effects.

As a workaround, add a PaintListener to your Button. On this Listener's paintControl method, get the generated event's GC and, with it, re-write the text of your Button using the color you want.

You can, in fact, draw anything over your Button.

这篇关于如何设置SWT按钮的前景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆