Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java can't see all installed fonts in system

Tags:

java

fonts

awt

birt

I have listed all available fonts in system by calling

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Font[] fontNames = graphicsEnvironment.getAllFonts();
    for (Font s : fontNames) {
        System.out.println(s);
    }

On console I can see many fonts but the list looks very uncomplete. For example: My OS has installed the "System" font but in output I can't see that font:

...
java.awt.Font[family=Sylfaen,name=Sylfaen,style=plain,size=1]
java.awt.Font[family=Symbol,name=Symbol,style=plain,size=1]
java.awt.Font[family=Tahoma,name=Tahoma,style=plain,size=1]
...

Installed fonts (sorry for polish OS): enter image description here

Why is that?

Another thing is that in WordPad I can see "System" font. However in MS Word 2010 "System" font is not available.

The problem is not with this particular "System" font. There are several fonts installed but missing in Java.

EDIT: Why am I asking? My application use BIRT Report Designer to generate .rpt files with reports templates. Next I use these files to render Swing components like JLabel, JTextField etc. Main problem is: User can generate report with fields that use font that Java Swing can't handle.

The part of sample xml file generated by BIRT:

<property name="fieldName">Blablabla{Label}</property>
<property name="fontFamily">"System"</property>
<property name="fontSize">16pt</property>

Our customer requirment specifies that font can't differ between generated report and Java swing components.

What I want to do is either handle all system fonts in Java or exclude in BIRT fonts which java can't handle.

like image 970
kukis Avatar asked Mar 27 '14 08:03

kukis


People also ask

How do you find all available fonts in your system Java?

Answer: To list all the fonts available to you in a Java application (a Java Swing application), use the GraphicsEnvironment. getLocalGraphicsEnvironment().

Why can't I find my installed fonts?

Click Start, point to Settings, and then click Control Panel. Double-click Fonts. On the File menu, click Fonts to place a check mark.

How do you find all available fonts on your system?

View Installed Fonts In Windows 10 or 11, type Control Panel in the search field and select it from the results. With Control Panel in Icon View, click the Fonts icon. Windows displays all the installed fonts.

How do I add different fonts to Java?

To add your own font to your JDK 1.1 Runtime, you need to create a charset converter and specify it in the font. properties file . The following example illustrates how to add your own platform font to the Java serif font. In this example, your font contains 256 glyphs, which are indexed 0 - 0xff.


1 Answers

The JVM doesn't necessarily use the fonts installed on your System, It is being shipped with its own fonts with you can see at

JAVA_HOME/jre/lib/fonts

For you to use a font with the JVM you need create the fonts and add them to the directory above or add the directory of the new fonts to your class path.

Alternatively, you can package the fonts with your jar archive file, Download fonts here

http://cooltext.com/Fonts-Gothic

or the Microsoft true Type fonts.

like image 164
JohnTheBeloved Avatar answered Sep 16 '22 11:09

JohnTheBeloved