Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stigkj/365909 to your computer and use it in GitHub Desktop.
Save stigkj/365909 to your computer and use it in GitHub Desktop.
public static void setSwingFontDefault(javax.swing.plaf.FontUIResource newFont) {
java.util.Enumeration<Object> uiManagerKeys = UIManager.getDefaults().keys();
while (uiManagerKeys.hasMoreElements()) {
Object key = uiManagerKeys.nextElement();
Object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource)
UIManager.put(key, newFont);
}
}
//Example call
setSwingFontDefault(new FontUIResource("Serif", Font.PLAIN, 16));
//Or to directly set a font for just ONE component, such as Labels
UIManager.put("Label.font",new Font("Serif",Font.ITALIC,12));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment