Reputation: 4644
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):
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.
Upvotes: 18
Views: 17382
Reputation: 61
can you try this?, and ensure that you are using the latest JDK 7
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontFamilies = ge.getAvailableFontFamilyNames();
for (String ff : fontFamilies) {
System.out.println(ff);
}
}
Upvotes: 5
Reputation: 11
I had the same issue while working with JavaFX. In Windows when you install a font, by default it's not located in
%windir%\Fonts
as expected but instead in
%homepath%\AppData\Local\Microsoft\Windows\Fonts
It seems that some classes in java doesn't check the fonts installed in user folder. Try installing the font in question by right clicking on it and choosing "Install for all users". (See the Screenshot)
Upvotes: 1
Reputation: 4143
One some Windows machines there are two buttons for installing fonts: Install For Me and Install For All Users. Java only lists fonts installed for all users.
Upvotes: 9
Reputation: 2433
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
or the Microsoft true Type fonts.
Upvotes: 8
Reputation: 13
Yes, JVM does not contain all the fonts. You need to install all the core fonts manually. If you are using a Linux then this should help you :
Upvotes: 1