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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor