如何设置SWT按钮的前景色? [英] How to set SWT button foreground color?
问题描述
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屋!