ceTe Software Help Library for Java August - 2020
DynamicPDF Generator for Java / Programming with Generator for Java / Fonts And Text / Font Families
In This Topic
    Font Families
    In This Topic

    Font families are a grouping of four styles of fonts (regular, bold, italic, and bold italic). These are used by the FormattedTextArea class to change fonts and specify styles. Five font families are included and accessed through static properties of the FontFamily class:

    • FontFamily.getTimes() - Times Font Family
    • FontFamily.getHelvetica() - Helvetica Family
    • FontFamily.getCourier() - Courier Family
    • FontFamily.getSymbol() - Symbol Family
    • FontFamily.getZapfDingbats() - Zapf Dingbats Font Family

    Note: The Symbol and Zapf Dingbats have the same font specified to all four font styles. New font families can be created by instantiating a FontFamily class and specifying the fonts for each style. These can include any of the 14 built-in fonts or TrueType fonts.

    New font families can be created by passing four Font objects into a FontFamilies constructor. The name specified in the constructor is the name used to specify the font in a FormattedTextArea.

    [Java]
        // Create four TrueType fonts.
        TrueTypeFont verdana = new TrueTypeFont("Verdana.ttf");
        TrueTypeFont verdanaBold = new TrueTypeFont("Verdanab.ttf");
        TrueTypeFont verdanaItalic = new TrueTypeFont("Verdanai.ttf");
        TrueTypeFont verdanaBoldItalic = new TrueTypeFont("Verdanaz.ttf");
        // Create a font family for Verdana.
        FontFamily verdanaFontFamily = new FontFamily("Verdana", verdana, verdanaBold,
                                                       verdanaItalic, verdanaBoldItalic);
    

    Note: In order to use a created font family in an FormattedTextArea you must add it through the FormattedTextArea's getFontFaces property.

    [Java]
        // Add the font family creaded above to an Formatted text area.
        formattedTextArea.getFontFaces().add(verdanaFontFamily);
    
    See Also