Pin It

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 :


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot