Java Program to Check Which Fonts are Available in a Local System

This is a Java program to know which fonts are available in a local system.

Problem Description

We have to write a program in Java such that it generates a list of fonts available in a Local System using GraphicsEnvironment.

Expected Input and Output

For knowing which fonts are available in a Local System, we can have the following set of input and output.
To know the fonts available: On the execution of the program, it is expected that a list is generated which contains the name of fonts available in the local system.

Problem Solution

1. Create a variable to get the local graphics environment from GraphicsEnvironment class. The GraphicsEnvironment class contains a collection of GraphicsDevice objects and Font objects available in a Local or Remote platform.
2. Get List of Font Family available using getAvailableFontFamilyNames() method.
3. Display the list.

Program/Source Code

Here is source code of the Java Program to get the list of font available in a local system. The program is successfully compiled and tested using javac compiler on Fedora 30.

  1. /* Java Program to get list of fonts available*/
  2. import java.awt.GraphicsEnvironment;
  3. class Fonts_Available
  4. {
  5. 	//Driver Function
  6. 	public static void main(String[] args)
  7. 	{
  8. 		//Get the local graphics environment
  9. 		GraphicsEnvironment local_env; 
  10.                 local_env= GraphicsEnvironment.getLocalGraphicsEnvironment();
  11. 		//Get available font names
  12. 		String allfonts[] = local_env.getAvailableFontFamilyNames();
  13. 		//Display the list of fonts
  14. 		for(int i=0;i<allfonts.length;i++)
  15. 			System.out.println(allfonts[i]);
  16. 	}
  17. }
Program Explanation

1. Variable local_env gets the local graphics environment.
2. Use getAvailableFontFamilyNames() to get the fonts available and store it in an string array.
3. Display the array.

advertisement
advertisement
Runtime Test Cases

Here’s the run time test case for generating list of fonts available in a Local System.

Test case 1 – Here’s the runtime output to get the list of fonts available. The program displays the list which contains the name of fonts available in the local system.

$ java Fonts_Available 
Abyssinica SIL
Bitstream Charter
C059
Caladea
Cantarell
Cantarell Extra Bold
Cantarell Light
Cantarell Thin
Carlito
cmex10
cmmi10
cmr10
cmsy10
Comfortaa
Comfortaa Light
Courier 10 Pitch
Cursor
D050000L
DejaVu Sans
DejaVu Sans Condensed
DejaVu Sans Light
DejaVu Sans Mono
DejaVu Serif
DejaVu Serif Condensed
Dialog
DialogInput
Droid Sans
Droid Sans Arabic
Droid Sans Armenian
Droid Sans Devanagari
Droid Sans Ethiopic
Droid Sans Fallback
Droid Sans Georgian
Droid Sans Hebrew
Droid Sans Japanese
Droid Sans Tamil
Droid Sans Thai
esint10
eufm10
FreeMono
FreeSans
FreeSerif
Jomolhari
Khmer OS
Khmer OS Content
Khmer OS System
Latin Modern Math
Liberation Mono
Liberation Sans
Liberation Serif
LM Mono 10
LM Mono 12
LM Mono 8
LM Mono 9
LM Mono Caps 10
LM Mono Light 10
LM Mono Light Cond 10
LM Mono Prop 10
LM Mono Prop Light 10
LM Mono Slanted 10
LM Roman 10
LM Roman 12
LM Roman 17
LM Roman 5
LM Roman 6
LM Roman 7
LM Roman 8
LM Roman 9
LM Roman Caps 10
LM Roman Demi 10
LM Roman Dunhill 10
LM Roman Slanted 10
LM Roman Slanted 12
LM Roman Slanted 17
LM Roman Slanted 8
LM Roman Slanted 9
LM Roman Unslanted 10
LM Sans 10
LM Sans 12
LM Sans 17
LM Sans 8
LM Sans 9
LM Sans Demi Cond 10
LM Sans Quot 8
Lohit Assamese
Lohit Bengali
Lohit Devanagari
Lohit Gujarati
Lohit Gurmukhi
Lohit Kannada
Lohit Odia
Lohit Tamil
Lohit Telugu
Meera
Mingzat
MnSymbol
Monospaced
Montserrat
Montserrat Black
Montserrat ExtraBold
Montserrat ExtraLight
Montserrat Light
Montserrat Medium
Montserrat SemiBold
Montserrat Thin
msam10
msbm10
Nimbus Mono PS
Nimbus Roman
Nimbus Sans
Nimbus Sans Narrow
Noto Color Emoji
Noto Sans CJK JP Black
Noto Sans CJK JP Bold
Noto Sans CJK JP DemiLight
Noto Sans CJK JP Light
Noto Sans CJK JP Medium
Noto Sans CJK JP Regular
Noto Sans CJK JP Thin
Noto Sans CJK KR Black
Noto Sans CJK KR Bold
Noto Sans CJK KR DemiLight
Noto Sans CJK KR Light
Noto Sans CJK KR Medium
Noto Sans CJK KR Regular
Noto Sans CJK KR Thin
Noto Sans CJK SC Black
Noto Sans CJK SC Bold
Noto Sans CJK SC DemiLight
Noto Sans CJK SC Light
Noto Sans CJK SC Medium
Noto Sans CJK SC Regular
Noto Sans CJK SC Thin
Noto Sans CJK TC Black
Noto Sans CJK TC Bold
Noto Sans CJK TC DemiLight
Noto Sans CJK TC Light
Noto Sans CJK TC Medium
Noto Sans CJK TC Regular
Noto Sans CJK TC Thin
Noto Sans Mono CJK JP Bold
Noto Sans Mono CJK JP Regular
Noto Sans Mono CJK KR Bold
Noto Sans Mono CJK KR Regular
Noto Sans Mono CJK SC Bold
Noto Sans Mono CJK SC Regular
Noto Sans Mono CJK TC Bold
Noto Sans Mono CJK TC Regular
Noto Sans Sinhala
Noto Sans Sinhala Blk
Noto Sans Sinhala Cond
Noto Sans Sinhala Cond Blk
Noto Sans Sinhala Cond ExtBd
Noto Sans Sinhala Cond ExtLt
Noto Sans Sinhala Cond Light
Noto Sans Sinhala Cond Med
Noto Sans Sinhala Cond SemBd
Noto Sans Sinhala Cond Thin
Noto Sans Sinhala ExtBd
Noto Sans Sinhala ExtCond
Noto Sans Sinhala ExtCond Blk
Noto Sans Sinhala ExtCond ExtBd
Noto Sans Sinhala ExtCond ExtLt
Noto Sans Sinhala ExtCond Light
Noto Sans Sinhala ExtCond Med
Noto Sans Sinhala ExtCond SemBd
Noto Sans Sinhala ExtCond Thin
Noto Sans Sinhala ExtLt
Noto Sans Sinhala Light
Noto Sans Sinhala Med
Noto Sans Sinhala SemBd
Noto Sans Sinhala SemCond
Noto Sans Sinhala SemCond Blk
Noto Sans Sinhala SemCond ExtBd
Noto Sans Sinhala SemCond ExtLt
Noto Sans Sinhala SemCond Light
Noto Sans Sinhala SemCond Med
Noto Sans Sinhala SemCond SemBd
Noto Sans Sinhala SemCond Thin
Noto Sans Sinhala Thin
Noto Serif CJK JP
Noto Serif CJK JP Black
Noto Serif CJK JP ExtraLight
Noto Serif CJK JP Light
Noto Serif CJK JP Medium
Noto Serif CJK JP SemiBold
Noto Serif CJK KR
Noto Serif CJK KR Black
Noto Serif CJK KR ExtraLight
Noto Serif CJK KR Light
Noto Serif CJK KR Medium
Noto Serif CJK KR SemiBold
Noto Serif CJK SC
Noto Serif CJK SC Black
Noto Serif CJK SC ExtraLight
Noto Serif CJK SC Light
Noto Serif CJK SC Medium
Noto Serif CJK SC SemiBold
Noto Serif CJK TC
Noto Serif CJK TC Black
Noto Serif CJK TC ExtraLight
Noto Serif CJK TC Light
Noto Serif CJK TC Medium
Noto Serif CJK TC SemiBold
Nuosu SIL
OpenSymbol
P052
Padauk
PakType Naskh Basic
PT Sans
PT Sans Narrow
rsfs10
SansSerif
Serif
Source Code Pro
Source Code Pro Black
Source Code Pro ExtraLight
Source Code Pro Light
Source Code Pro Medium
Source Code Pro Semibold
STIX
stmary10
Symbola
TeX Gyre Adventor
TeX Gyre Bonum
TeX Gyre Bonum Math
TeX Gyre DejaVu Math
TeX Gyre Pagella
TeX Gyre Pagella Math
TeX Gyre Schola Math
TeX Gyre Termes Math
TeXGyreChorus
TeXGyreCursor
TeXGyreHeros
TeXGyreHerosCn
TeXGyreSchola
TeXGyreTermes
URW Bookman
URW Gothic
Utopia
Waree
wasy10
Z003

Sanfoundry Global Education & Learning Series – Java Programs.

advertisement
If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.