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  .  ja v a2 s  .  co m*/
        Font uiManagerFont;
        UIDefaults uiDefaults;

        // Setup
        uiObject = null;
        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("MyJSQLView_Utils setUIManager() " + curObj.toString());

            if (curObj.toString().indexOf("font") != -1) {
                // System.out.println("MyJSQLView_Utils setUIManager() " + curObj);
                UIManager.put(curObj,
                        new FontUIResource(uiManagerFont.getFontName(),
                                uiManagerFont.getStyle(), fontSize));
            }
        }
    }
}

Related

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