Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to display information about available fonts in Java Swing API

Program to display available fonts :
package com.hubberspot.graphics.example;

import java.awt.*;
import javax.swing.*;

public class FontsInfo
{
  JFrame frame;
  JTextArea textarea;

  FontsInfo()
  {
    frame = new JFrame();
    frame.setLayout(new FlowLayout());
    textarea = new JTextArea();
  
    String[] font = GraphicsEnvironment
    .getLocalGraphicsEnvironment()
   .getAvailableFontFamilyNames();
  
    String temp = "";
  
    for (String name : font)
    {  
      temp = temp + name+"\n";
    }   
  
    textarea.setText(temp);
  
    frame.add(textarea);
    frame.setTitle("Welcome to Hubberspot!.");
    frame.setSize(300,600);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

  public static void main(String[] args)
  {
    new FontsInfo(); 
  }
}

Output of the program :


 
© 2021 Learn Java by Examples Template by Hubberspot