Set font for JLabel in Java
Description
The following code shows how to set font for JLabel.
Example
import java.awt.Font;
import java.awt.GraphicsEnvironment;
// ww w .j a v a 2 s . com
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame {
private String textMessage = "java2s.com";
public Main() {
Font font = new Font("Jokerman", Font.PLAIN, 35);
JLabel textLabel = new JLabel(textMessage);
textLabel.setFont(font);
getContentPane().add(textLabel);
setVisible(true);
}
public static void main(String[] args) {
JFrame frame = new Main();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »