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

王林
Release: 2023-09-10 10:21:02
forward
1492 people have browsed it

To change the text font, you can use the setFont() method of JLabel -

label.setFont(new Font("Verdana", Font.PLAIN, 12));
Copy after login

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); } }
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template