Connor Neville Connor Neville - 1 year ago 79
Java Question

Setting the Default Font of Swing Program

I was wondering how to set the default font for my entire Java swing program. From my research it appears it can be done with

, something to do with
, but I can't find specifically how to do it, and the
appears pretty complicated.

Answer Source


public static void setUIFont (javax.swing.plaf.FontUIResource f){
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get (key);
      if (value != null && value instanceof javax.swing.plaf.FontUIResource)
        UIManager.put (key, f);

Call by ...

setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download