Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strike through java.awt.Font

Tags:

java

swing

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

like image 493
richs Avatar asked Jul 01 '09 19:07

richs


People also ask

What fonts are in Java awt font?

Logical Fonts Java defines five logical font families that are Serif, SansSerif, Monospaced, Dialog, and DialogInput. It must be supported by the JRE. Note that JRE maps the logical font names to physical font because these are not the actual font libraries.

How do you strikethrough in Java?

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.

What is the strikethrough font?

Strikethrough is a font effect that causes text to appear as though it is crossed out. For example, this text should have a line through the middle of it. The strikethrough effect may be enabled through font properties if a program supports it, or applied to text on a web page using the HTML or CSS.

What font is used in Java?

All implementations of the Java Platform must support TrueType fonts; support for other font technologies is implementation dependent. Physical fonts may use names such as Helvetica, Palatino, HonMincho, or any number of other font names.


2 Answers

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); 
like image 114
richs Avatar answered Oct 14 '22 07:10

richs


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.

like image 34
AlbertoPL Avatar answered Oct 14 '22 07:10

AlbertoPL