Say I have a Swing JComponent and I set a Font for the text of that JComponent. I build the project and create a .jar file of my project. Now, If I run this jar file from another computer where the Font is not install, what will be happen? Will the jar automatically install the Font or I need to make some kind of checking to do that? Thank you.
If you need to use that specific font, you'll have to make sure it's installed on the machine before your jar file is run, or load it yourself. There's nothing that will automatically install the font for you. You can retrieve the list of available fonts using this code:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String [] fonts = ge.getAvailableFontFamilyNames();
Alternatively, you can load and register the font yourself using
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font f = Font.createFont(Font.TRUETYPE_FONT, new File(pathToYourTTFFile));
ge.registerFont(f);
You should check the return code of registerFont
and catch/deal with the exceptions thrown by createFont
.
No there isn't any automatic method. You have to install font manually however you may get the available fonts using,
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] names = ge.getAvailableFontFamilyNames();
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