Java Swing Font Size setUIManagerFont(int fontSize)

Here you can find the source of setUIManagerFont(int fontSize)

Description

set UI Manager Font

License

Open Source License

Declaration

public static void setUIManagerFont(int fontSize) 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.awt.Font;

import java.util.Iterator;

import java.util.Set;

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

public class Main {
    public static void setUIManagerFont(int fontSize) {
        // Method Instances
        Object uiObject;/*w  w w . j a v a2 s  .c o m*/
        Font uiManagerFont;
        UIDefaults uiDefaults;

        // Setup
        uiObject = UIManager.get("Label.font");

        if (uiObject != null && uiObject instanceof Font)
            uiManagerFont = (Font) uiObject;
        else
            return;

        if (uiManagerFont.getSize() == fontSize)
            return;

        // Collect the UI Manager keys that are fonts
        // and update them to the new font size.

        uiDefaults = UIManager.getLookAndFeelDefaults();
        Set<Object> hash = uiDefaults.keySet();
        Iterator<Object> iterator = hash.iterator();

        while (iterator.hasNext()) {
            Object curObj = iterator.next();
            // System.out.println("LindyFrame_Utils setUIManager() " + curObj.toString());

            if (curObj.toString().indexOf("font") != -1) {
                /*
                System.out.println("LindyFrmae_Utils setUIManager() " + curObj + "\n"
                                    + "Font Name: " + uiManagerFont.getFontName() + "\n"
                                    + "Name: " + uiManagerFont.getName() + "\n"
                                    + "Style: " + uiManagerFont.getStyle() + "\n"
                                    + "Size: " + fontSize);
                 */

                if (fontSize > 16)
                    UIManager.put(curObj,
                            new FontUIResource(uiManagerFont.getName(),
                                    Font.PLAIN, fontSize));
                else
                    UIManager.put(curObj,
                            new FontUIResource(uiManagerFont.getName(),
                                    uiManagerFont.getStyle(), fontSize));
            }
        }
    }
}

Related

  1. setFontSize(JLabel label, int i)
  2. setFontSizeForComponent(JComponent component, int newFontSize)
  3. setLookAndFeel(int fontSize)
  4. setUIFontSize(float size)
  5. setUIManagerFont(int fontSize)