List all available fonts in the system : Graphic Environment « 2D Graphics GUI « Java

List all available fonts in the system

List all available fonts in the system

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class AllAvailableFontsComboBox extends JPanel {

  JComboBox fonts;

  public AllAvailableFontsComboBox() {
    add(new JLabel("Fonts"));

    GraphicsEnvironment gEnv = GraphicsEnvironment
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    Vector vector = new Vector();
    for (int i = 1; i < envfonts.length; i++) {
    fonts = new JComboBox(vector);

  public static void main(String s[]) {
    JFrame f = new JFrame("FontSelection");
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
    AllAvailableFontsComboBox fontSelection = new AllAvailableFontsComboBox();
    f.getContentPane().add(fontSelection, BorderLayout.CENTER);
    f.setSize(new Dimension(350, 250));


Related examples in the same category

1.A quick utility to print out graphic device informationA quick utility to print out graphic device information
2.Show all fonts you have in your systemShow all fonts you have in your system
3.Determine if full-screen mode is supported directly
4.Leave full-screen mode (Return to normal windowed mode)
5.Enter full screen mode
6.Getting Screen Sizes
7.Getting Refresh Rates
8.Getting Number of Colors
9.Getting the Current Screen Refresh Rate and Number of Colors
10.Listing All Available Font Families
11.Getting the Font Faces for a Font Family
12.Create buffered images that are compatible with the screen
13.Create an image that does not support transparency from GraphicsConfiguration
14.Create an image that supports transparent pixels from GraphicsConfiguration
15.Getting Amount of Free Accelerated Image Memory
16.Get the available font family names
17.Get the available font names
18.Retrieve and print the graphic device information
19.Create an image that supports arbitrary levels of transparency from GraphicsConfiguration
20.Setting the Screen Size, Refresh Rate, or Number of Colors
21.If more than one screen is available, gets the size of each screen
22.Getting the Number of Screens
23.Get the GraphicsEnvironment and GraphicsDeviceGet the GraphicsEnvironment and GraphicsDevice
24.extends JComponent to exercise Graphics