简体   繁体   English

Synth覆盖按钮上的文字绘制

[英]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中实现paintButtonBorderpaintButtonBacground ,但是我想知道是否有一种方法可以对文本进行处理? 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)并返回您的实例按钮SynthStylegetGraphicsUtils(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>标记开头)时要警惕某些细节:

  1. The super implementation will paint ss.getComponent().getText() instead of text . 超级实现将绘制ss.getComponent().getText()而不是text
  2. The super implementation will manually set the text color before painting. 超级实现将在绘画之前手动设置文本颜色。 For unstyled text, this will be 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM