Home  >  Article  >  Web Front-end  >  How to change JLabel's text font using HTML in Java?

How to change JLabel's text font using HTML in Java?

王林
王林forward
2023-09-10 10:21:021454browse

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 -

Example

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

Output

How to change JLabels text font using HTML in Java?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete