Our users run our Java GUI app on their Windows desktops, and we're planning a switch from Oracle Java 8 to OpenJDK 8. But we've found that different OpenJDK builds are inconsistent in the quality of the font rendering, with Oracle and AdoptOpenJDK being equivalent but Red Hat severely lacking.
The following screenshot shows a simple Java AWT/Swing program on Windows on the three different JDKs:
- Oracle 1.8.0_201-b26
- AdoptOpenJDK 1.8.0_202-b08
- Red Hat 1.8.0_201-2-redhat-b09
There's some problem with the rendering in the Red Hat JDK, because every character is distorted.
The program is just displaying a Swing JLabel with the command-line-specified Dialog/bold/12 font (which each JDK maps to the Windows OS Arial font):
// fontname.groovy
import javax.swing.*
import java.awt.Font
import sun.font.*
styles=[bold:Font.BOLD,italic:Font.ITALIC,plain:Font.PLAIN]
SwingUtilities.invokeLater({
l = new JLabel("${args}: ${System.getProperty('java.runtime.name')} ${System.getProperty('java.runtime.version')}")
l.setFont(new Font(args[0],styles[args[1]],Integer.valueOf(args[2])))
f = new JFrame()
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
f.getContentPane().setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10))
f.getContentPane().add(l)
f.pack()
f.setVisible(true)
logicalFont = l.getGraphics().getFont()
print(logicalFont)
physicalFont = FontManagerFactory.getInstance().findFont2D( logicalFont.getName(), 0, FontManager.NO_FALLBACK )
print(physicalFont)
})
The additional screenshot below shows the same font on 3 Swing PLAFs available on this Windows system and shows that the appearance under Red Hat OpenJDK is consistent for each PLAF (set via system property option -Dswing.defaultlaf=
):
- Default Look and Feel (javax.swing.plaf.metal.MetalLookAndFeel)
- Windows Look and Feel (com.sun.java.swing.plaf.windows.WindowsLookAndFeel)
- Nimbus Look and Feel (javax.swing.plaf.nimbus.NimbusLookAndFeel)
Does anyone know why the Red Hat OpenJDK build would render fonts in a way that's so different? Is it possibly some additional JDK configuration or setup that the Red Hat OpenJDK might require?