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:
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.
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.