Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What font in Swing looks the same in all OS?

I use Netbeans 7.0 with JDK6 under Windows 7 to design the user interface of my Java application. I apply System look and feel. But it looks the way I want in Windows but differs in MacOS and even worse, it looks different in different window managers in Linux (LXDE, GNOME, KDE, XFCE).

By different I mean the fonts look and their size. In Windows, if a label looks "v 1.23", it looks like "v ..." in other OSes because the fonts become bigger in that OS and the JLabel do not have enough place to show. This happens in several places.

I don't want to increase the label width. I want the label to look the same in that given width in all OS. By default, Netbeans uses the font Tahoma 11pt on my pc. I think it's not available in all OSes so the other OSes use different font.

Is Arial a common font?

Should I change the font of every element to Arial manually? Or any other options?

like image 775
Vigneshwaran Avatar asked Aug 25 '11 09:08

Vigneshwaran


2 Answers

Instead, use a layout manager and a logical font family. This example with the Font below adds 24-point italic serif text to the center of a (default) BorderLayout to achieve a pleasing result on disparate platforms.

ta.setFont(new Font("Serif", Font.ITALIC, 24));

Mac OS X:

Mac

Windows 7:

Windows

Ubuntu Linux:

Linux

like image 155
trashgod Avatar answered Oct 19 '22 23:10

trashgod


When it comes to window managers there is a lot more to it than just font size, for instance the width between 2 controls are handled differently in gnome & KDE. when it comes down to using the same font size across all platforms you can use Sans Serif font, this is available in all the OS'es I've worked with.

it would also be better (if you can't find serif in an OS where you want to run your app) you can download a font (free ones from GNU Free Fonts).

when it comes to setting the font sizes & the fonts, why don't you try using a theme & set the font there... you can use the UIManager.setLookAndFeel() method to change themes. here is a link on Look & Feel

like image 22
Anantha Sharma Avatar answered Oct 20 '22 00:10

Anantha Sharma