Example usage for javax.swing.text StyleContext getFont

List of usage examples for javax.swing.text StyleContext getFont

Introduction

In this page you can find the example usage for javax.swing.text StyleContext getFont.

Prototype

public Font getFont(String family, int style, int size) 

Source Link

Document

Gets a new font.

Usage

From source file:processing.app.Theme.java

/**
 * Returns the default font for text areas.
 *
 * @return The default font.//from  w  w w. j  a va 2 s.co  m
 */
public static final Font getDefaultFont() {

    // Use StyleContext to get a composite font for better Asian language
    // support; see Sun bug S282887.
    StyleContext sc = StyleContext.getDefaultStyleContext();
    Font font = null;

    if (OSUtils.isMacOS()) {
        // Snow Leopard (1.6) uses Menlo as default monospaced font,
        // pre-Snow Leopard used Monaco.
        font = sc.getFont("Menlo", Font.PLAIN, 12);
        if (!"Menlo".equals(font.getFamily())) {
            font = sc.getFont("Monaco", Font.PLAIN, 12);
            if (!"Monaco".equals(font.getFamily())) { // Shouldn't happen
                font = sc.getFont("Monospaced", Font.PLAIN, 13);
            }
        }
    } else {
        // Consolas added in Vista, used by VS2010+.
        font = sc.getFont("Consolas", Font.PLAIN, 13);
        if (!"Consolas".equals(font.getFamily())) {
            font = sc.getFont("Monospaced", Font.PLAIN, 13);
        }
    }

    // System.out.println(font.getFamily() + ", " + font.getName());
    return font;
}