Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to read system fonts?

  Asked By: Jasmine    Date: Jan 21    Category: Java    Views: 1608
  

Is there any way to read system fonts through java?
I want to create a file input stream through reading *.ttf file.
I can able to get a collection of fonts using
GraphicsEnvironment().getAllFonts().
I donot want fonts collection. i want to create font input stream.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Helene Stewart     Answered 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 ....

 
Didn't find what you were looking for? Find more on How to read system fonts? Or get search suggestion and latest updates.




Tagged: