devxlogo

Obtaining the List of Available Fonts

Some applications allow the user to select which font is used for displaying text. To do this, you need to be able to dynamically determine which fonts are available so that the user can select the one that they wish to use. Fortunately, Java provides a simple way of obtaining this information through the Toolkit class. This method will return ajava.awt.Choice instance that is populated with the names of the available fonts:

 public java.awt.Choice getFontChoice() {	java.awt.Choice choice = new java.awt.Choice();	Toolkit tk = Toolkit.getDefaultToolkit();	String[] fontnames = tk.getFontList();	for (int i = 0; i < fontnames.length; i++) {		choice.addItem(fontnames[i]);	}  //  for (int i = 0; i < fontnames.length; i++)	return choice;}  //  public java.awt.Choice getFontChoice()

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.