如何设置 SWT 按钮的前景色? [英] How to set SWT button foreground color?
问题描述
SWT Button 类有一个 setForeground(Color)
方法,但它似乎没有效果(该方法实际上是在 Button 的超类上).javadoc 说这个方法是一个提示,可能会被平台覆盖.我的平台是 Windows.
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.
- 这是否意味着无法在 Windows 上设置按钮前景色?
- 它是否适用于其他平台?
- 有解决方法吗?
推荐答案
在 Windows 上,Buttons
的 setForeground
没有效果.
On Windows, setForeground
for Buttons
has no effects.
作为一种解决方法,将 PaintListener
添加到您的 Button
.在此侦听器的 paintControl
方法上,获取生成事件的 GC
并使用它使用您想要的颜色重写 Button
的文本.
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.
事实上,您可以在 Button
上绘制任何内容.
You can, in fact, draw anything over your Button
.
这篇关于如何设置 SWT 按钮的前景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!