简体   繁体   English

删除线 java.awt.Font

[英]Strike through java.awt.Font

Is there a way to make a java.awt.Font strike through?有没有办法让 java.awt.Font 删除线?

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); 

underline and strikethrough examples in awt. awt中的下划线和删除线示例。

http://www.java2s.com/Code/Java/2D-Graphics-GUI/TextAttributeUnderlineandstrikethrough.htm 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. 基本上,从字符串中创建一个新的AttributedString,添加一个STRIKETHROUGH属性,然后绘制。

NOTE: This will NOT make the FONT strikethrough, but you can set the text to that font and then strikethrough on the text. 注意:这不会使FONT删除,但您可以将文本设置为该字体,然后在文本上删除。 This is simply another way of doing it. 这只是另一种方式。 Rich's answer actually makes the font strikethrough. Rich的答案实际上使字体删除了。

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. 设计器还允许您更改字体,以便您可以验证是否可以使用您要使用的字体。

Use this用这个

yourTextView.setPaintFlags(holder.name.getPaintFlags() |
Paint.STRIKE_THRU_TEXT_FLAG);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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