Example usage for java.awt GraphicsEnvironment getAvailableFontFamilyNames

List of usage examples for java.awt GraphicsEnvironment getAvailableFontFamilyNames

Introduction

In this page you can find the example usage for java.awt GraphicsEnvironment getAvailableFontFamilyNames.

Prototype

public abstract String[] getAvailableFontFamilyNames();

Source Link

Document

Returns an array containing the names of all font families in this GraphicsEnvironment localized for the default locale, as returned by Locale.getDefault() .

Usage

From source file:MainClass.java

public static void main(String[] a) {
    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontnames = e.getAvailableFontFamilyNames();
    for (String s : fontnames) {
        System.out.println(s);//from w ww.  j  a  v  a 2s. com
    }
}

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String familyNames[] = ge.getAvailableFontFamilyNames();

    for (String familyName : familyNames) {
        System.out.println("Family names: " + familyName);
    }//w  w w.  j  a v a  2  s .c  o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String fontNames[] = ge.getAvailableFontFamilyNames();

    for (int i = 0; i < fontNames.length; i++) {
        System.out.println(fontNames[i]);
    }/*ww  w.j av a  2s.c  om*/
}

From source file:Main.java

public static void main(String[] args) {

    GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontnames = e.getAvailableFontFamilyNames();
    System.out.println("\nFonts available on this platform: ");
    for (int i = 0; i < fontnames.length; i++)
        System.out.println(fontnames[i]);

    return;/*  w  w  w.j a v  a 2s.co  m*/
}

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fonts = ge.getAvailableFontFamilyNames();
    JComboBox<String> fontChooser = new JComboBox<>(fonts);
    fontChooser.setRenderer(new FontCellRenderer());
    JOptionPane.showMessageDialog(null, fontChooser);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int cp = 0;/*from   w w  w.  j a  v  a 2 s. c  o  m*/
    StyledDocument doc;
    JTextPane jta = new JTextPane();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    doc = jta.getStyledDocument();
    JScrollPane jsp = new JScrollPane(jta);
    jsp.setPreferredSize(new Dimension(400, 400));
    String[] fnt = ge.getAvailableFontFamilyNames();
    MutableAttributeSet mas = jta.getInputAttributes();
    for (int i = 0; i < fnt.length; i++) {
        StyleConstants.setBold(mas, false);
        StyleConstants.setItalic(mas, false);
        StyleConstants.setFontFamily(mas, fnt[i]);
        StyleConstants.setFontSize(mas, 16);

        doc.insertString(cp, fnt[i] + "\n", mas);

        StyleConstants.setBold(mas, true);
        doc.insertString(cp, fnt[i] + "bold \n", mas);
        StyleConstants.setItalic(mas, true);

        doc.insertString(cp, fnt[i] + "bold and italic\n", mas);
        StyleConstants.setBold(mas, false);
        doc.insertString(cp, fnt[i] + "italic\n", mas);
    }
    JFrame frm = new JFrame();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setLayout(new BorderLayout());
    frm.add(jsp, BorderLayout.CENTER);
    frm.setLocation(100, 100);
    frm.pack();
    frm.setVisible(true);
}

From source file:components.ListDialogRunner.java

/**
 * Finds a cursive font to use, or falls back to using
 * an italic serif font.//from  w  w w  .j a  v  a 2  s .  com
 */
protected static Font getAFont() {
    //initial strings of desired fonts
    String[] desiredFonts = { "French Script", "FrenchScript", "Script" };

    String[] existingFamilyNames = null; //installed fonts
    String fontName = null; //font we'll use

    //Search for all installed font families.  The first
    //call may take a while on some systems with hundreds of
    //installed fonts, so if possible execute it in idle time,
    //and certainly not in a place that delays painting of
    //the UI (for example, when bringing up a menu).
    //
    //In systems with malformed fonts, this code might cause
    //serious problems; use the latest JRE in this case. (You'll
    //see the same problems if you use Swing's HTML support or
    //anything else that searches for all fonts.)  If this call
    //causes problems for you under the latest JRE, please let
    //us know.
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    if (ge != null) {
        existingFamilyNames = ge.getAvailableFontFamilyNames();
    }

    //See if there's one we like.
    if ((existingFamilyNames != null) && (desiredFonts != null)) {
        int i = 0;
        while ((fontName == null) && (i < desiredFonts.length)) {

            //Look for a font whose name starts with desiredFonts[i].
            int j = 0;
            while ((fontName == null) && (j < existingFamilyNames.length)) {
                if (existingFamilyNames[j].startsWith(desiredFonts[i])) {

                    //We've found a match.  Test whether it can display 
                    //the Latin character 'A'.  (You might test for
                    //a different character if you're using a different
                    //language.)
                    Font f = new Font(existingFamilyNames[j], Font.PLAIN, 1);
                    if (f.canDisplay('A')) {
                        fontName = existingFamilyNames[j];
                        System.out.println("Using font: " + fontName);
                    }
                }

                j++; //Look at next existing font name.
            }
            i++; //Look for next desired font.
        }
    }

    //Return a valid Font.
    if (fontName != null) {
        return new Font(fontName, Font.PLAIN, 36);
    } else {
        return new Font("Serif", Font.ITALIC, 36);
    }
}

From source file:es.emergya.cliente.constants.LogicConstantsUI.java

private static Font getFont(Integer type, String font) {
    Font f;/*from w  ww.  ja v a2  s  . c  o  m*/
    try {
        f = Font.createFont(Font.TRUETYPE_FONT, LogicConstantsUI.class.getResourceAsStream(font));
    } catch (Exception e) {
        LogicConstantsUI.LOG.error("No se pudo cargar el font bold", e);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();
        if (fontNames.length > 0) {
            f = Font.decode(fontNames[0]);
            if (type != null) {
                f = f.deriveFont(type);
            }
        } else {
            throw new NullPointerException("There is no font available: " + font);
        }
    }
    return f;
}

From source file:es.emergya.cliente.constants.LogicConstants.java

private static Font getFont(Integer type, String font) {
    Font f;/*from w  ww  .  j a v  a  2  s . c o m*/
    try {
        f = Font.createFont(Font.TRUETYPE_FONT, LogicConstants.class.getResourceAsStream(font));
    } catch (Exception e) {
        LogicConstants.LOG.error("No se pudo cargar el font bold", e);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();
        if (fontNames.length > 0) {
            f = Font.decode(fontNames[0]);
            if (type != null) {
                f = f.deriveFont(type);
            }
        } else {
            throw new NullPointerException("There is no font available: " + font);
        }
    }
    return f;
}

From source file:AllAvailableFontsComboBox.java

public AllAvailableFontsComboBox() {
    add(new JLabel("Fonts"));

    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    Vector vector = new Vector();
    for (int i = 1; i < envfonts.length; i++) {
        vector.addElement(envfonts[i]);/*from   w  ww. j  av  a 2s .co  m*/
    }
    fonts = new JComboBox(vector);
    add(fonts);
}