通过 java.awt.Font 删除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1070878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:02:39  来源:igfitidea点击:

Strike through java.awt.Font

javaswing

提问by richs

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

有没有办法让 java.awt.Font 穿透?

回答by richs

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

回答by AlbertoPL

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. This is simply another way of doing it. Rich's answer actually makes the font strikethrough.

注意:这不会使 FONT 删除线,但您可以将文本设置为该字体,然后在文本上删除线。这只是另一种方式。Rich 的回答实际上使字体带有删除线。

回答by camickr

In case you are interested in what other text attributes are available you can use the Visual Font Designerto 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.

如果您对其他可用的文本属性感兴趣,您可以使用可视字体设计器来试验不同的属性以查看它们的外观。设计器还允许您更改字体,以便您可以验证删除线是否可用于要使用的字体。