Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change text font for JLabel with HTML in Java?
To change text font, you can use the setFont() method of JLabel −
label.setFont(new Font("Verdana", Font.PLAIN, 12));
The following is an example to change text font for JLabel with 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("<html><font size=+1>" + "<center>ABC</html>");
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

Advertisements