How can I change the font of all components that are displayed in my java application?
I tried it using the UIManager
UIManager.put("TextField.font", new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 11));
UIManager.put("Label.font", new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 11));
UIManager.put("ComboBox.font", new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 11))
Oddly enough this changed the font of the textfield but did not work for JLabels or JComboBoxes
Then I tried to set the font by looping over all keys the UIManager knows:
public static void setUIFont(FontUIResource f) {
Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
FontUIResource orig = (FontUIResource) value;
Font font = new Font(f.getFontName(), orig.getStyle(), f.getSize());
FontUIResource fontUIResource = new FontUIResource(font);
UIManager.put(key, fontUIResource);
UIManager.getDefaults().put(key, fontUIResource);
UIManager.getLookAndFeel().getDefaults().put(key, fontUIResource);
}
}
}
This code did not work at all.
I must say that I use Synthetica as LookAndFeel... so I don't know how that interferes with my manuell settings via UIManager.