JAVA - How To Change A Jlabel Font Color, Name, Style, And Size In Java
Source Code:
package JavaDB_001;
import java.awt.Color;
import java.awt.Font;
import javax.swing.*;
public class Project extends JFrame{
JLabel label;
public Project(){
super("Change JLabel Font Name, Style, Size, Color");
label = new JLabel("This Is My Text Here");
//"TimesRoman" = font name;
//Font.ITALIC = font style, You Can Also Put An Int;
// 20 = size;
Font f = new Font("TimesRoman",Font.BOLD,25);
//change a jlabel font color
label.setForeground(Color.red);
//set the font to the Jlabel
//set the font to the Jlabel
label.setFont(f);
label.setBounds(80,20,250,80);
setLayout(null);
add(label);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(400,200);
setVisible(true);
}
public static void main(String[] args){
new Project();
//to know some font style number
System.out.println(Font.BOLD);
System.out.println(Font.CENTER_BASELINE);
System.out.println(Font.HANGING_BASELINE);
System.out.println(Font.ITALIC);
System.out.println(Font.LAYOUT_LEFT_TO_RIGHT);
System.out.println(Font.LAYOUT_NO_LIMIT_CONTEXT);
System.out.println(Font.LAYOUT_NO_START_CONTEXT);
System.out.println(Font.LAYOUT_RIGHT_TO_LEFT);
System.out.println(Font.PLAIN);
System.out.println(Font.ROMAN_BASELINE);
System.out.println(Font.TRUETYPE_FONT);
System.out.println(Font.TYPE1_FONT);
}
}
/////////////////////////OUTPUT:
Change A Jlabel Font Color, Name, Style, And Size In Java |
1
1
2
2
0
4
2
1
0
0
0
1
Download Projects Source Code