Java JLabel set font

Description

Java JLabel set font


import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main extends JFrame {

  public Main() {
    super("Link JLabel with JTextField");

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JLabel nameLabel = new JLabel("Java demo from demo2s.com.");
    // create new Font
    Font font = new Font("Courier", Font.BOLD, 12);

    // set font for JLabel
    nameLabel.setFont(font);//from w w  w.  j a v  a2  s. c om

    add(nameLabel);

  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}



PreviousNext

Related