This tutorial highlights the API for displaying the list of font families available in your system using Java. You can get the font families using getAvailableFontFamilyNames() method of the local GraphicsEnvironment. The GraphicsEnvironment
class describes the collection of GraphicsDevice
objects and Font
objects available to a Java(tm) application on a particular platform. Lets look at the example:
FontListExample.java
package javabeat.net.core; import java.awt.GraphicsEnvironment; public class FontListExample { public static void main(String[] args) { GraphicsEnvironment graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] listOfFontFamilyNames = graphicsEnv.getAvailableFontFamilyNames(); for (int i = 0; i < listOfFontFamilyNames.length; i++) { System.out.println("Font Name " + (i + 1) + ":" + listOfFontFamilyNames[i]); } } }
Output…
Font Name 1:Bitstream Charter Font Name 2:Bitstream Vera Sans Font Name 3:Bitstream Vera Sans Mono Font Name 4:Bitstream Vera Serif Font Name 5:Century Schoolbook L Font Name 6:Courier 10 Pitch Font Name 7:DejaVu Sans Font Name 8:DejaVu Sans Condensed Font Name 9:DejaVu Sans Light Font Name 10:DejaVu Sans Mono Font Name 11:DejaVu Serif Font Name 12:DejaVu Serif Condensed Font Name 13:Dialog Font Name 14:DialogInput Font Name 15:Dingbats Font Name 16:FreeMono Font Name 17:FreeSans Font Name 18:FreeSerif Font Name 19:gargi Font Name 20:Garuda Font Name 21:KacstArt Font Name 22:KacstBook Font Name 23:KacstDecorative Font Name 24:KacstDigital Font Name 25:KacstFarsi Font Name 26:KacstLetter Font Name 27:KacstNaskh Font Name 28:KacstOffice Font Name 29:KacstOne Font Name 30:KacstPen Font Name 31:KacstPoster Font Name 32:KacstQurn Font Name 33:KacstScreen Font Name 34:KacstTitle Font Name 35:KacstTitleL Font Name 36:Kedage Font Name 37:Khmer OS Font Name 38:Khmer OS System Font Name 39:Kinnari Font Name 40:Liberation Mono Font Name 41:Liberation Sans Font Name 42:Liberation Sans Narrow Font Name 43:Liberation Serif Font Name 44:Lohit Bengali Font Name 45:Lohit Gujarati Font Name 46:Lohit Hindi Font Name 47:Lohit Punjabi Font Name 48:Lohit Tamil Font Name 49:Loma Font Name 50:Mallige Font Name 51:Meera Font Name 52:Monospaced Font Name 53:mry_KacstQurn Font Name 54:Mukti Narrow Font Name 55:NanumGothic Font Name 56:NanumMyeongjo Font Name 57:Nimbus Mono L Font Name 58:Nimbus Roman No9 L Font Name 59:Nimbus Sans L Font Name 60:Norasi Font Name 61:OpenSymbol Font Name 62:Phetsarath OT Font Name 63:Pothana2000 Font Name 64:Purisa Font Name 65:Rachana Font Name 66:Rekha Font Name 67:Saab Font Name 68:SansSerif Font Name 69:Sawasdee Font Name 70:Serif Font Name 71:Standard Symbols L Font Name 72:Symbol Font Name 73:TakaoPGothic Font Name 74:Tlwg Typist Font Name 75:Tlwg Typo Font Name 76:TlwgMono Font Name 77:TlwgTypewriter Font Name 78:Ubuntu Font Name 79:Ubuntu Condensed Font Name 80:Ubuntu Light Font Name 81:Ubuntu Mono Font Name 82:Umpush Font Name 83:UnBatang Font Name 84:UnDinaru Font Name 85:UnDotum Font Name 86:UnGraphic Font Name 87:UnGungseo Font Name 88:UnPilgi Font Name 89:Untitled1 Font Name 90:URW Bookman L Font Name 91:URW Chancery L Font Name 92:URW Gothic L Font Name 93:URW Palladio L Font Name 94:utkal Font Name 95:Vemana2000 Font Name 96:Waree Font Name 97:WenQuanYi Micro Hei Font Name 98:WenQuanYi Micro Hei Mono