Perfect Abstractions
  • Home
  • Contact
  • Blog
  • Home
  • Contact
  • Blog

How to Install Windows Fonts in Java on Linux

7/28/2014

17 Comments

 
Java does a pretty good job at making applications look the same on Windows and Linux. But the default fonts that Java uses on Linux are not the same fonts used for Windows. This causes a problem for implementing GUI projects on Linux that will be used on Windows. The default font used on Linux can have different dimensions than the fonts used on Windows causing differences in the flow of text and messing up components in windows. Here is an example:
Picture
Default font on Windows.
Picture
Default font on Linux
The solution is to install and use Microsoft's free "TrueType core fonts for the Web" on Linux and configure Java to use those fonts.
You might wonder if it is legal to install these Microsoft fonts on a Linux computer. The answer is yes it is legal. And you don't have to own any copies of Windows. The license for these fonts is short and easy to read. You can read it here: https://www.microsoft.com/typography/fontpack/eula.htm The key parts of the license are, "The SOFTWARE PRODUCT is licensed, not sold." and "You may install and use an unlimited number of copies of the SOFTWARE PRODUCT."
Here are instructions on how to install and configure Java to use these fonts on Ubuntu Linux. These instructions work for Oracle Java 7, Oracle Java 8 and OpenJDK 7.
  1. Using your package manager install the "ttf-mscorefonts-installer" package.
  2. Open this file in a text editor, "/etc/fonts/conf.avail/60-latin.conf". Add the "Times New Roman" font family to the top of the list for the "serif" fonts. Add the "Arial" family to the top of the list for the "sans-serif" fonts. Add "Courier New" to the top of the list for the "monospace" fonts. Or use my version of the file: 60-latin.conf. Save and close the file.
  3. Run this command to update fonts: "sudo dpkg-reconfigure fontconfig"
  4. The new fonts will not be used if an operating system specific Java fontconfig property file exists that matches the operating system being used. If such a file exists it must be removed. Here is an example of removing such a file: "sudo rm /usr/lib/jvm/java-7-oracle/jre/lib/fontconfig.Ubuntu.properties".
  5. That is it, the next time you launch a Java application the Windows fonts will be used.
Thanks to Kyle Chase and pphillips for providing information about how to do this on the IA Forum topic Java Fonts and Linux.
I would love to hear your experiences about installing Windows fonts in Java on Linux. Leave a comment about your experience or about this article.
Did you find this blog post useful? Sign up for my mailing list to get notified of future blog posts.
17 Comments
Abu Junayd
8/20/2014 03:41:21 pm

I recently switched from Windows to Ubuntu and was thinking of going back to Windows because of the horrible looking fonts in the java software I'm working on.

The steps you outlined worked for me. Thanks so much!

Reply
Nick Mudge
8/21/2014 01:06:02 am

Hi Abu,
I am so glad that this worked for you and you didn't have to go back to Windows. Thanks for sharing your experience.

Reply
Dennis Leblanc
12/5/2014 04:05:39 am

I followed these steps but unfortunately my Dialog fonts still don't look right on lInux. I am running Lubuntu 14.04, Ignition 7.7.1 and Java 1.8.0_25

If I switch my font from Dialog to Arial specifically, then it displays properly, so I know the font is installed, and I can see the fonts in /usr/share/fonts/truetype, it's just not being used as the default for Dialog.

Reply
Nick Mudge link
12/5/2014 04:27:41 am

Okay, did you delete this file: /usr/lib/jvm/java-8-oracle/jre/lib/fontconfig.Ubuntu.properties ?

Reply
rodrigo
5/21/2015 01:30:39 am

Worked like a charm, thank you

Reply
Klaus
9/3/2015 01:55:50 am

Many thanks for the instructions! Now the application looks in Linux like in Windows.

Reply
Shawn Linderman link
11/1/2015 01:59:17 pm

Worked for me with RHEL 6.7 on vm, thanks!

I have to get it working on AIX 7.1, though, too. Dunno if Linux msttcorefonts RPM can be installed on AIX, but if it can, then it looks like configuring $JAVA_FONTS variable to the fonts might work...at least for Java apps running on AIX 7.1...

Reply
John
2/16/2016 11:57:51 am

I tried to edit the file but it wouldn't let me. I'm guessing I'll have to chmod the file in order to edit it.

Could you included the steps to do this and let us know if we have to close or reload something to get it to start working?

Thanks

Reply
Ammar Akouri
5/23/2016 02:40:21 pm

Man you just did me a hude favor ! Thank you so much !

Reply
AlThePal link
11/19/2016 01:08:09 pm

Be aware that in later versions of Linux (Mint 18 for example), the DejaVu font files start with a lower number in /etc/fonts/conf.avail and so have a higher priority then 60-latin.conf. You should either comment out the relevant sections of the DejaVu files or rename the Latin file to a lower number and create a new soft link in /etc/fonts/conf.d.

Reply
Nancy Malhotra link
5/18/2017 01:55:40 am

WuInstall - Manage Windows Updates

WuInstall is a command line tool that makes it possible to install Windows Updates on demand. This gives you full control over the patching process. You decide what patches should be applied when and on which machine.

Depending on the System configuration it uses either the internal WSUS server or the external Microsoft Update Server to look for available updates. Afterwards those can be downloaded and installed.

WuInstall was first released in 2009 and today it is used by ten thousands companies all over the world; amongst them are a lot of big enterprises across all industries and public institutions.

Reply
kosmos890
11/6/2017 08:47:14 am

Hi Nick

I have installed ttf-mscorefonts-installer package,
I have edited /etc/fonts/conf.avail/60-latin.conf,
I delete /usr/lib/jvm/java-8-oracle/jre/lib/fontconfig.Ubuntu.properties
and I run dpkg-reconfigure fontconfig
but it does not work (Xubuntu 16.04 - java 1.8.0_151-b12)

I downloaded fontconfig.Ubuntu1404.properties from
https://forum.inductiveautomation.com/t/java-fonts-and-linux/1112/24
and it works.

I prefer the first method because I choose my favorite font family.
Can you help me?

Reply
Nick Mudge
11/6/2017 09:11:52 am

Hi kosmos890,

I am sorry, I want to help you but I don't have any suggestion about it.

Reply
kosmos890
11/6/2017 09:56:58 am

Thanks for your reply Nick.
The second way (fontconfig.Ubuntu1404.properties) helps me a lot

Martin
2/11/2019 09:15:24 am

Even this is an old post. I ran into "the same".

"Arial" was not found.

I searched and found:
* https://packages.debian.org/de/jessie/ttf-mscorefonts-installer

Since I am using Debian 9/stretch this was right.

Edited my sources.list (added contrib), installed the package and I were done.

My case:
* Debian 9
* JasperReports ("stand alone version", came from a friend)
* OpenJDK 8u181

Reply
Tadeu
8/2/2019 03:41:50 am

Thanks a lot, it is 2019 and I was having this problem... the solution was:

sudo apt-get install ttf-mscorefonts-installer

cp -r /usr/share/fonts/truetype/msttcorefonts $JAVA_HOME/lib/fonts

sudo dpkg-reconfigure fontconfig

Make sure that $JAVA_HOME is used by your application, otherwise you will need to copy those fonts folder over all jvm avaiable on the machine

Reply
Nina the Nomad link
12/17/2020 05:03:38 pm

Appreciate your bblog post

Reply



Leave a Reply.

    Author

    Nick Mudge
    Ignition Software Consultant
    nick@perfectabstractions.com
    916.234.6521

    See our blogs here http://blog.perfectabstractions.com
    nickmudge.info.

    Links

    Nick Mudge's Weblog
    Computing Without Boundaries

    Archives

    March 2017
    November 2016
    September 2015
    August 2015
    January 2015
    September 2014
    August 2014
    July 2014

    Categories

    All
    Applets
    Chat
    Debugging
    Fonts
    Gateway Scripting
    Ignition
    Ignition 7.7
    Ignition Modules
    Ignition Scripting
    Ignition Templates
    Java
    Jython
    Kepware
    Linux
    Logging
    OPC
    OPC UA
    OPC-UA
    Python
    RSS
    SCADA
    Security
    Software Abstraction
    Support
    Testing
    Water
    Weather
    Weather Radar
    Windows

    RSS Feed

    Join My Mailing List

    • Get email updates about news, blog posts, articles, product offers and other items of interest.

    • subscribed: 0
    • I respect your privacy
    • Email Marketingby GetResponse
© Perfect Abstractions LLC