To change the size and/or style of a font, you call its deriveFont() method : Font « 2D Graphics « Java Tutorial






  1. deriveFont(int Style): Creates a new Font object with the style specified - one of PLAIN, BOLD, ITALIC, or BOLD+ITALIC
  2. deriveFont(float size): Creates a new Font object with the size specified
  3. deriveFont(int Style, float size): Creates a new Font object with the style and size specified
To change the size and/or style of a font, you call its deriveFont() method
import java.awt.BorderLayout;
import java.awt.Font;

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

public class DrivedFont {
  public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Pick to Change Background");

    Font myFont = new Font("Serif", Font.ITALIC | Font.BOLD, 12);
    Font newFont = myFont.deriveFont(50F);

    button.setFont(newFont);
    f.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
  }
}








16.23.Font
16.23.1.java.awt.Fontjava.awt.Font
16.23.2.Creating Serif FontCreating Serif Font
16.23.3.Create Bold and Italic fontCreate Bold and Italic font
16.23.4.Show fonts with mouse click
16.23.5.To change the size and/or style of a font, you call its deriveFont() methodTo change the size and/or style of a font, you call its deriveFont() method
16.23.6.Display font info.
16.23.7.To get all available fonts in your system
16.23.8.To get the font names
16.23.9.Show all Fonts installed in your systemShow all Fonts installed in your system
16.23.10.Fonts exercise: a font chooserFonts exercise: a font chooser
16.23.11.Display font in a grid
16.23.12.Create font from true type font
16.23.13.System fonts displaySystem fonts display