Java JButton set font

Description

Java JButton set font

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());

    JButton bn = new JButton("Close");

    Font font = bn.getFont().deriveFont(Font.ITALIC);
    bn.setFont(font);//from   w w  w.ja  va  2 s  .  co m
    
    getContentPane().add(bn);
  }

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



PreviousNext

Related