Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jasmine Grant   on Jan 21 In Java Category.

  
Question Answered By: Helene Stewart   on Jan 21

If you want to find out that hows many fonts  are there on the
system then that can be easily find out.

I have written a small program , I hope this should work for you .

import java.awt.*;
import javax.swing.*;
import java.util.*;
public class Fontfind extends JPanel
{

public Fontfind()
{
this.setLayout(new BorderLayout());
JLabel l1=new JLabel("L1");
JLabel l2=new JLabel("L2");
JLabel l3=new JLabel("L3");
l1.setFont(new Font("Arial",Font.PLAIN,22));
Map map=l1.getFont().getAttributes();
Object[] arr=map.keySet().toArray();
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]+","+map.get(arr[i]));
}

this.add(l1,BorderLayout.NORTH);
this.add(l2,BorderLayout.CENTER);
this.add(l3,BorderLayout.SOUTH);
}
public static void main(String[] args)
{
Fontfind fontfind1 = new Fontfind();
String nm = (String) java.security.AccessController.doPrivileged
(new sun.security.action.GetPropertyAction
("java.awt.graphicsenv", null));
System.out.println(" The Srcurity Manager is"+ nm);
Font[] fonts=GraphicsEnvironment.getLocalGraphicsEnvironment
().getAllFonts();
for(int i=0;i<fonts.length;i++)
{
System.out.println(" hte Fonts Name is "+fonts[i].getName
());
}
JFrame f=new JFrame();
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(fontfind1,BorderLayout.CENTER);
f.setSize(300,300);
f.show();
}

Lets me know if this doen't work ....

Share: