In .net, for the Font class, you can directly use constants to generate underlined fonts.
However, in Java, it is a little more complicated to generate an underlined font, and you need to use the TextAttribute class to generate it. (Recommended: java video tutorial)
Please refer to the code snippet below for details.
// 生成带有下划线的字体 // 需要借助于TextAttribute类来处理 HashMap<TextAttribute, Object> hm = new HashMap<TextAttribute, Object>(); hm.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); // 定义是否有下划线 hm.put(TextAttribute.SIZE, 12); // 定义字号 hm.put(TextAttribute.FAMILY, "Simsun"); // 定义字体名 Font font = new Font(hm); // 生成字号为12,字体为宋体,字形带有下划线的字体
TextAttribute instances are used as attribute keys to identify attributes in Font, TextLayout, AttributedCharacterIterator, and other classes that handle text attributes. Other constants defined in this class can be used as property values.
UNDERLINE_ON:
public static final Integer UNDERLINE_ON
Standard underline.
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of How to make fonts display underline in java. For more information, please follow other related articles on the PHP Chinese website!