3
votes

In my Swing application I use Arial font. Unfortunately it is rendered differently on different platforms:

Windows:

Windows variant

Mac OS X:

enter image description here

Linux:

enter image description here

Windows and Mac OS X variants look almost the same. Linux is quite different and seems to be not an Arial at all. Main problem is the different width of letters...

What would be the best solution that would render text similar to Windows variant on Linux? Probably some alternative fonts like for example Nimbus Sans L?

Some limitations: JRE cannot be supplied with the application and it should be very close to Arial.

Thanks!

4
pastebin.com/C6NcGP0t You can use that to then switch out the fonts, or else you could just save it as an image and buffer an image instead.user1181445
If you want to be cross-platform, do not insist on the same font. And why should you?Raedwald
@Raedwald, main reason: letter width breaks layout at some places.Andrej
"breaks layout" Fix the layout.Andrew Thompson
Layout is already OK and not under discussion. Please stick to the original question.Andrej

4 Answers

5
votes

Embrace platform variety. Given that different platforms have similar fonts with different metrics, let each component do the work of calculating its own preferred size by not interfering and by using layouts correctly. Here's a nice example with screenshots.

2
votes

One solution may be load the font file using Font.createFont(). Here's a sample.

0
votes

You can install Microsoft's free fonts on Linux and use them in Java. This includes an Arial font. This blog post shows you how: How to Install Windows Fonts in Java on Linux