Java Swing Font Set setUIFont(Font f)

Here you can find the source of setUIFont(Font f)

Description

Tries to set the font to the whole swing interface.

License

Open Source License

Parameter

Parameter Description
f a parameter

Declaration

public static void setUIFont(Font f) 

Method Source Code

//package com.java2s;
/*/*from ww  w.  ja va 2s . c  om*/
 * This file is part of JCool.
 *
 * JCool is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JCool is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JCool.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright ? 2011 Eneko Sanz Blanco <nkogear@gmail.com>
 *
 */

import java.awt.Font;

import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

public class Main {
    /**
     * Tries to set the font to the whole swing interface. However, some L&F
     * ommit font settings and use their own one. This usually happens with
     * system L&Fs, which use the system's fonts. Therefore, it's not recommended
     * to use it. But you can still change the JCool components default font
     * with the methods this class provides. The rest swing JComponents will
     * retain their font.
     *
     * @param f
     */
    public static void setUIFont(Font f) {
        java.util.Enumeration keys = UIManager.getDefaults().keys();
        FontUIResource fontResource = new FontUIResource(f);
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value != null && value instanceof FontUIResource)
                UIManager.put(key, fontResource);
        }
        UIManager.put("defaultFont", fontResource);
    }
}

Related

  1. setSwingFont(Font font)
  2. setTitleLabelFont(JLabel label)
  3. setUIDefaultFont()
  4. setUIFont(final Font font)
  5. setUIFont(final Font font)
  6. setUIFont(Font fon)
  7. setUIFont(FontUIResource f)
  8. setUIFont(FontUIResource f)
  9. setUIFont(FontUIResource f)