tags:

views:

597

answers:

3

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

+5  A: 

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.

AlbertoPL
+4  A: 

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);
richs
Will this work for all fonts? I couldn't figure that out.
AlbertoPL
+1  A: 

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.

camickr