Java Swing Font Set setFont(@Nonnull final Font font)

Here you can find the source of setFont(@Nonnull final Font font)

Description

Sets default Swing font.

License

Open Source License

Parameter

Parameter Description
font the new font to use

Declaration

public static void setFont(@Nonnull final Font font) 

Method Source Code

//package com.java2s;

import java.awt.Font;

import java.util.Enumeration;

import javax.annotation.Nonnull;

import javax.swing.UIManager;

import javax.swing.plaf.FontUIResource;

public class Main {
    /**/*w w w  .  jav  a2 s.  co m*/
     * Sets default Swing font.
     * IMPORTANT! Needs to be called before main frame creation
     *
     * @param font the new font to use
     */
    public static void setFont(@Nonnull final Font font) {
        final FontUIResource f = new FontUIResource(font);
        final Enumeration keys = UIManager.getDefaults().keys();

        while (keys.hasMoreElements()) {
            final Object key = keys.nextElement();
            final Object value = UIManager.get(key);

            if (value instanceof FontUIResource) {
                UIManager.put(key, f);
            }
        }
    }
}

Related

  1. setBorderFromFont(JComponent c)
  2. setComponentsFont(Container container, Font font)
  3. setDefaultFont(final Font font)
  4. setDefaultFont(Font font)
  5. setDefaultFont(java.awt.Font font)
  6. setFont(Container container)
  7. setFont(Font font)
  8. setFont(HTMLDocument doc, Font font, Color fg)
  9. setFont(String fontName)