Jump to Real's How-to Main page

Change component default font

public static void setUIFont (javax.swing.plaf.FontUIResource f){
    //
    // sets the default font for all Swing components.
    // ex. 
    //  setUIFont (new javax.swing.plaf.FontUIResource
    //   ("Serif",Font.ITALIC,12));
    //
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get (key);
      if (value instanceof javax.swing.plaf.FontUIResource)
        UIManager.put (key, f);
      }
    }    
For a particuliar component
UIManager.put("Label.font",new Font("Serif",Font.ITALIC,12));
Swing UI default
If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]