Get All Installed Fonts in a PC

An example on getting the list of all installed fonts in your PC in Font[] and String[].

import java.awt.*;
class GetFonts
{
public static void main(String args[])
{

/*

Deprecated
-------------------------

String[] fonts=Toolkit.getDefaultToolkit().getFontList();
for(String font:fonts)
{
System.out.println(font);
}

*/

// Replaced with..
GraphicsEnvironment g=GraphicsEnvironment.getLocalGraphicsEnvironment();

String[] fonts=g.getAvailableFontFamilyNames();

for(String font:fonts)
{
System.out.println(font);
}

/*

To get the Font objects instead of just names..
---------------------------------------------------------

Font[] fonts=g.getAllFonts();

for(Font font:fonts)
{
System.out.println(font);
}

*/

}
}

java.awt.GraphicsEnvironment class is an abstract class whose object can be created by using the public static method in it, getLocalGraphicsEnvironment(). This object contains methods, and the one that i've used here to get font family names is getAvailableFontFamilyNames() which returns a String[] containing the names of the fonts that are available (installed) in your PC. If you want the Font[] which represents java.awt.Font objects for use to set font for components, then you can use getAllFonts() method. The Toolkit class has also got it's own method getFontList() which returns the names of fonts installed in the form of a String[] however, that is now deprecated.

Your output might look different because it depends on the fonts installed in your PC. Happy coding :)

Also see my posts on Get Screen Size and Resolution in JavaCreating Beep Sound in Java and finally AWT Tutorial in Java

All installed fonts


Aharoni
Aldhabi
Andalus
Angsana New
AngsanaUPC
Aparajita
Arabic Typesetting
Arial
Arial Black
Batang
BatangChe
Browallia New
BrowalliaUPC
Calibri
Calibri Light
Cambria
Cambria Math
Candara
Comic Sans MS
Consolas
Constantia
Corbel
Cordia New
CordiaUPC
Courier New
DaunPenh
David
DFKai-SB
Dialog
DialogInput
DilleniaUPC
DokChampa
Dotum
DotumChe
Ebrima
Estrangelo Edessa
EucrosiaUPC
Euphemia
FangSong
Franklin Gothic Medium
FrankRuehl
FreesiaUPC
Gabriola
Gadugi
Gautami
Georgia
Gisha
Gulim
GulimChe
Gungsuh
GungsuhChe
Impact
IrisUPC
Iskoola Pota
JasmineUPC
KaiTi
Kalinga
Kartika
Khmer UI
KodchiangUPC
Kokila
Lao UI
Latha
Leelawadee
Levenim MT
LilyUPC
Lucida Bright
Lucida Console
Lucida Sans
Lucida Sans Typewriter
Lucida Sans Unicode
Malgun Gothic
Mangal
Marlett
Meiryo
Meiryo UI
Microsoft Himalaya
Microsoft JhengHei
Microsoft JhengHei UI
Microsoft New Tai Lue
Microsoft PhagsPa
Microsoft Sans Serif
Microsoft Tai Le
Microsoft Uighur
Microsoft YaHei
Microsoft YaHei UI
Microsoft Yi Baiti
MingLiU
MingLiU-ExtB
MingLiU_HKSCS
MingLiU_HKSCS-ExtB
Miriam
Miriam Fixed
Mongolian Baiti
Monospaced
MoolBoran
MS Gothic
MS Mincho
MS PGothic
MS PMincho
MS UI Gothic
MV Boli
Myanmar Text
Narkisim
Nirmala UI
NSimSun
Nyala
Palatino Linotype
Plantagenet Cherokee
PMingLiU
PMingLiU-ExtB
Raavi
Rod
Sakkal Majalla
SansSerif
Segoe Print
Segoe Script
Segoe UI
Segoe UI Light
Segoe UI Semibold
Segoe UI Semilight
Segoe UI Symbol
Serif
Shonar Bangla
Shruti
SimHei
Simplified Arabic
Simplified Arabic Fixed
SimSun
SimSun-ExtB
Sylfaen
Symbol
Tahoma
Times New Roman
Traditional Arabic
Trebuchet MS
Tunga
Urdu Typesetting
Utsaah
Vani
Verdana
Vijaya
Vrinda
Webdings
Wingdings


Posted by at on

Tags: Abstract Window Toolkit,