Java Swing Font Set setUIDefaultFont()

Here you can find the source of setUIDefaultFont()

Description

set UI Default Font

License

Open Source License

Declaration

public static final void setUIDefaultFont() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Font;
import java.awt.GraphicsEnvironment;

import java.util.Enumeration;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

public class Main {
    public static final void setUIDefaultFont() {

        Font defaultFont = null;//from w w  w  .j a v  a  2 s. c  om

        // Search font
        GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fonts = e.getAllFonts(); // Get the fonts
        for (Font f : fonts) {

            if ("verdana".equals(f.getFontName().toLowerCase())) {
                defaultFont = f;
                break;
            }
        }

        if (defaultFont == null) {
            return;
        }

        Enumeration<Object> keys = UIManager.getDefaults().keys();

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

            if (value != null && value instanceof FontUIResource) {
                FontUIResource oldFUR = (FontUIResource) value;

                UIManager.put(key,
                        new FontUIResource(defaultFont.getFontName(), oldFUR.getStyle(), oldFUR.getSize()));
            }

        }
    }
}

Related

  1. setItalicFont(JComponent jcomp)
  2. setLabelProperties(JLabel label, Color color, Font font, Color bg)
  3. setMonospacedFont(JComponent component)
  4. setSwingFont(Font font)
  5. setTitleLabelFont(JLabel label)
  6. setUIFont(final Font font)
  7. setUIFont(final Font font)
  8. setUIFont(Font f)
  9. setUIFont(Font fon)