Strike through java.awt.Font

后端 未结 3 1688
Happy的楠姐
Happy的楠姐 2021-02-12 16:46

Is there a way to make a java.awt.Font strike through?

相关标签:
3条回答
  • 2021-02-12 17:19

    underline and strikethrough examples in awt.

    http://www.java2s.com/Code/Java/2D-Graphics-GUI/TextAttributeUnderlineandstrikethrough.htm

    Basically, create a new AttributedString out of your string, add a STRIKETHROUGH attribute, and draw.

    NOTE: This will NOT make the FONT strikethrough, but you can set the text to that font and then strikethrough on the text. This is simply another way of doing it. Rich's answer actually makes the font strikethrough.

    0 讨论(0)
  • 2021-02-12 17:24

    In case you are interested in what other text attributes are available you can use the Visual Font Designer to experiment with different attributes to see how they look. The designer also allows you to change the Font so you can verify if the strike through is available for the Font you want to use.

    0 讨论(0)
  • 2021-02-12 17:35

    So i found this, which works.

    Font font = new Font("helvetica", Font.PLAIN, 12);
    Map  attributes = font.getAttributes();
    attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    Font newFont = new Font(attributes); 
    
    0 讨论(0)
提交回复
热议问题