
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
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
- Related Articles
- How to change JLabel font in Java
- How to change text font in HTML?
- How can we implement a JLabel text with different color and font in Java?
- Java Program to change JLabel text after creation
- How to change font size with HTML in Java Swing JEditorPane?
- How to set font for text in JTextPane with Java?
- How to create JLabel to hold multiline of text using HTML in Java?
- How to change JLabel size in Java?
- Java Program to set alignment for text in JLabel
- How to change font size in HTML?
- How to set text font family in HTML?
- How to align JLabel text vertically top in Java?
- How to set the font family for text with JavaScript?
- How to change JLabel background and foreground color in Java?
- How do you change the default font color for all text in Matplotlib?

Advertisements