Java AWT Font create font and set to JButton

Description

Java AWT Font create font and set to JButton

import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Main extends JFrame {
  public Main() {
    super("JButton");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());

    //from   w  w w.  j a v  a2s .  c  om
    JButton bn = new JButton("Close");
    Font font = new Font("Arial", Font.BOLD, 15);
    bn.setFont(font);

    getContentPane().add(bn);
  }

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



PreviousNext

Related