Sets the default Font for the current UIManager - Java 2D Graphics

Java examples for 2D Graphics:Font

Description

Sets the default Font for the current UIManager

Demo Code


//package com.java2s;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;

import java.util.Enumeration;

public class Main {
    /**//from ww w .  j  a va  2  s .  co  m
     * Sets the default Font for the current UIManager
     *
     * @param fon the new Font
     */
    public static void setUIFont(Font fon) {
        FontUIResource f = new FontUIResource(fon);
        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);
            }
        }
        for (Window w : Window.getWindows()) {
            SwingUtilities.updateComponentTreeUI(w);
        }
    }
}

Related Tutorials