Java Swing Font Set setFontScale(float scale)

Here you can find the source of setFontScale(float scale)

Description

set Font Scale

License

Open Source License

Declaration

public static void setFontScale(float scale) 

Method Source Code


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

import java.awt.Font;
import java.util.HashMap;
import java.util.Map;
import javax.swing.UIManager;

public class Main {
    private static Map<String, Font> originals;

    public static void setFontScale(float scale) {

        if (originals == null) {
            originals = new HashMap<>(25);
            for (Map.Entry entry : UIManager.getDefaults().entrySet()) {
                Object key = entry.getKey();
                if (key.toString().toLowerCase().contains(".font")) {
                    Object value = entry.getValue();
                    Font font = null;

                    if (value instanceof Font) {
                        font = (Font) value;
                        originals.put(key.toString(), font);
                    }//from  w  ww.ja  va 2 s. c om
                }
            }
        }

        for (Map.Entry<String, Font> entry : originals.entrySet()) {
            String key = entry.getKey();
            Font font = entry.getValue();

            float size = font.getSize();
            size *= scale;

            font = font.deriveFont(Font.PLAIN, size);
            UIManager.put(key, font);
        }
    }
}

Related

  1. setFont(Container container)
  2. setFont(Font font)
  3. setFont(HTMLDocument doc, Font font, Color fg)
  4. setFont(String fontName)
  5. setFontRecursively(final JComponent component, final Font font, final boolean childsOnly)
  6. setHtmlFont(HTMLDocument doc, Font font)
  7. setItalicFont(JComponent jcomp)
  8. setLabelProperties(JLabel label, Color color, Font font, Color bg)
  9. setMonospacedFont(JComponent component)