Show all Fonts installed in your system : Font « 2D Graphics « Java Tutorial






Show all Fonts installed in your system
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class PaintAllFontsFromGraphicEvironment extends JPanel {
 
  public static void main(String[] a){
    JFrame f = new JFrame();
    f.setSize(400,400);
    f.add(new PaintAllFontsFromGraphicEvironment());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }
  
  public void paint(Graphics g) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    Font[] allFonts = ge.getAllFonts();

    for (int i = 0; i < allFonts.length; i++) {
      Font f = allFonts[i].deriveFont(10.0f);
      g.setFont(f);

      g.setColor(Color.black);
      g.drawString("Hello!", 10, 20*i);

    }
  }
}








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