Java Font Example in JLabel


Here example code to set font in JLabel:
package myjavaexample; 
 
import java.awt.Font; 
import javax.swing.BorderFactory; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.WindowConstants; 
 
public class MyJavaExample extends JFrame 
{ 
    public void openFrame() 
    { 
        JLabel label = new JLabel("Hello World!"); 
        Font font = new Font("Courier", Font.BOLD,28); 
        label.setFont(font); 
        label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10,10)); 
        add(label); 

        setTitle("Simple Image Preview"); 
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
        setSize(200,200); 
        setLocation(200,200); 
        pack(); 
        setVisible(true); 
    } 

    public static void main(String[] args) { 
        MyJavaExample mainwin=new MyJavaExample(); 
        mainwin.openFrame(); 
    } 
} 

Comments



Popular posts from this blog

Simple Java Code HTML Highlighter

How to Use Extends and Implements

Fibonacci Algorithm in Java Array