Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Font;

import java.util.Enumeration;

import javax.swing.UIManager;

import javax.swing.plaf.FontUIResource;

public class Main {
    /** Convenience method for {@link #setUIFont(Font)} */
    public static void setUIFont(String name, int style, int size) {
        final Font f = new Font(name, style, size);
        setUIFont(f);
    }

    /** 
     * Sets all used fonts for displaying to the specified font df
     * <br>Use with care! 
     */
    public static void setUIFont(final Font df) {

        setUIFontSize(df.getSize());
        final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
        while (keys.hasMoreElements()) {
            final Object key = keys.nextElement();
            final Object value = UIManager.get(key);
            if (value instanceof Font) {
                final Font ifont = (Font) value;
                final Font ofont = new FontUIResource(df.getName(), ifont.getStyle(), df.getSize());
                UIManager.put(key, ofont);
            }
        }
    }

    /** 
     * Adjust all fonts for displaying to the given size.
     * <br>Use with care!
     */
    public static void setUIFontSize(final int size) {

        final java.util.Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
        while (keys.hasMoreElements()) {
            final Object key = keys.nextElement();
            final Object value = UIManager.get(key);
            if (value instanceof Font) {
                final Font ifont = (Font) value;
                final Font ofont = ifont.deriveFont((float) size);
                UIManager.put(key, ofont);
            }
        }
    }
}