Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Helvetica in Java?

Tags:

java

fonts

Helvetica is available in one form or another on Windows, Mac OS X, and Linux. Under Windows, I can see it from Microsoft Word. On the two UNIX platforms, I can find it with xlsfonts | grep -i helvetica; the name seems to be adobe-helvetica.

But the JDK can't find it! It's not listed from GraphicsEnvironment.getAllFonts(), nor does it come up when I call new Font("Helvetica", ...) [using several name variants, either, like "Adobe Helvetica"]; instead I get defaulted to "Dialog" font and it seems to name it with whatever name I used.

This font is available on every relevant Java target platform today. How do I use it from within Java?

like image 651
skiphoppy Avatar asked Oct 16 '25 03:10

skiphoppy


1 Answers

Font f = new Font("Helvetica", Font.PLAIN, 10);  // make a new font object

ObjectName.setFont(f); // set the objects font using setFont();

where "Helvetica" is the font, Font.PLAIN defines the style, and 10 defines the size. Of course it must be installed to work, and you can bundle it using CreateFont().

Try the Java API for Fonts for more reference.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!