Ugly swing fonts under ratpoison
I am writing a small application in swing. I am usin开发者_如何学Cg Ratpoison as my window manager (with wmname LG3D) and Netbeans as IDE. My application fonts when started from KDE or directly from Netbeans look ok. Started from ratpoison they looks like this:
Screenshot http://img195.imageshack.us/img195/8079/swingfontsratpoison.png Click for full size
KDE is probably adding more fonts to the system when starting up.
Execute this on the KDE and in the ratpoison:
fc-list -v | grep "file:\|fullname:\|^$"
and compare the font list to see what is missing.
If some directory is missing, add it to the /etc/fonts/fonts.conf, in to a new entry.
If just missing some fonts, you can copy then to the ~/.fonts (assuming that you have this dir configures in fonts.conf)
if all fonts are the same, try to move all configs in /etc/fonts/conf.d to a temporary directory and run
fc-cache -f
and test.
if looks better, start adding back one more config, run the fc-cache -f again , restart again the java app and test.
repeat until you found the config that breaks the java fonts. In the end you should have all configs minus the one that breaks the java.
Usually its some config that sets a font as preferred, that java will blindly use, over better fonts.
Actually, you can use any system font in Swing.
Easily, just by adding one sentence: yourComponent.setFont(new Font("Tahoma", Font.BOLD|Font.ITALIC, 16));
Or you can change the overall settings: UIManager.put("label.font", new Font("Tahoma", Font.BOLD, 16));
The "keys" of the put method are usually strings indicating what you want to change like: label.font, button.font, label.color, textfield.font, etc. All in small cases.
And don't forget to import java.awt.Font AND/OR javax.swing.UIManager at the beginning!
精彩评论