Java JLabel set font from derived font

Description

Java JLabel set font from derived 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("Name:");

    nameLabel.setFont(nameLabel.getFont().deriveFont(Font.ITALIC | Font.BOLD));

    add(nameLabel);/*from w  w  w . java2s.  co  m*/

  }

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



PreviousNext

Related