To change the text font, you can use the setFont() method of JLabel -
label.setFont(new Font("Verdana", Font.PLAIN, 12));
The following is an example of changing the JLabel text font using HTML -
import java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Label Example"); JLabel label; label = new JLabel("" + "ABC"); label.setBounds(50, 50, 100, 30); label.setFont(new Font("Verdana", Font.PLAIN, 12)); frame.add(label); frame.setSize(500,300); frame.setLayout(null); frame.setVisible(true); } }
The above is the detailed content of How to change JLabel's text font using HTML in Java?. For more information, please follow other related articles on the PHP Chinese website!