Java 中下划线字体的常数值是多少?
Font.BOLD 粗体字体
Font.ITALIC 斜体字体
什么是 UNDERLINE 字体常量? 我尝试了所有可用的常量,但没有用。
最佳答案
假设您想要带下划线和粗体的 Serif 字体,大小 = 12。
Map<TextAttribute, Integer> fontAttributes = new HashMap<TextAttribute, Integer>();
fontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
Font boldUnderline = new Font("Serif",Font.BOLD, 12).deriveFont(fontAttributes);
如果您不想将其加粗,请使用 Font.PLAIN 而不是 Font.BOLD。不要使用 Font 类的 getAttributes() 方法。它会给你一个疯狂的通配符参数化类型 Map<TextAttribute,?>
,您将无法调用 put() 方法。有时 Java 会像那样令人讨厌。如果您对原因感兴趣,可以查看此站点:http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html
关于java - Java中下划线字体的常数值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/325840/