[英]Synth override text drawing on button
Is it possible to use painter or some other technique to customize text drawing on controls with synth? 是否可以使用painter或其他技术自定义带有合成器的控件上的文本绘制?
I know you can implement paintButtonBorder
and paintButtonBacground
in SynthPainter, but I was wondering is there a way to do it with text? 我知道您可以在SynthPainter中实现paintButtonBorder
和paintButtonBacground
,但是我想知道是否有一种方法可以对文本进行处理? Maybe some workaround? 也许一些解决方法?
Typically you would create a SynthGraphicsUtils
subclass, override paintText(SynthContext ss, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset)
and return an instance of your subclass from your button SynthStyle
's getGraphicsUtils(SynthContext context)
method. 通常,您将创建一个SynthGraphicsUtils
子类,重写paintText(SynthContext ss, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset)
并返回您的实例按钮SynthStyle
的getGraphicsUtils(SynthContext context)
方法的子类。
Anyway, if you are going to delegate painting to the super implementation, be wary of certain details if text
is in HTML (begins with the <html>
tag): 无论如何,如果您打算将绘画委派给超级实现,则当text
为HTML(以<html>
标记开头)时要警惕某些细节:
ss.getComponent().getText()
instead of text
. 超级实现将绘制ss.getComponent().getText()
而不是text
。 ss.getComponent().getForeground()
. 对于无样式的文本,这将是ss.getComponent().getForeground()
。 For styled text, this will match the color specified in HTML/CSS. 对于样式文本,这将与HTML / CSS中指定的颜色匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.