简体   繁体   中英

Strike through java.awt.Font

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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