I'm working with java.awt.Font , How can I discover if the font defined is installed on the system?
Specifically, I have
Font font = new Font("FooBar", 0, 14);
I want to discover if "font" is a valid font on the system and default to something more universal if it isn't available.
Try checking your Font in a loop like this:
public class SO2 {
public static void main(String args[]) {
GraphicsEnvironment g= null;
g=GraphicsEnvironment.getLocalGraphicsEnvironment();
String []fonts=g.getAvailableFontFamilyNames();
for (int i = 0; i < fonts.length; i++) {
System.out.println(fonts[i]);
if(fonts[i].equals("YOUR FONT")){
System.out.println("Found!");
}
}
}}
It should output "Found!" if it locates your font.
Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With