Hope this helps - you can then use something like this:
String fontName = "SansSerif";
        Font font = Font.getFont(fontName);
        UIManager.put("TextPane.font", font);
        UIManager.put("TextField.font", font);
        UIManager.put("TextArea.font", font);

Or for a StyledDocument:
   public static void applyLogicalStyle(JTextPane tp,StyledDocument doc)
    {
        Style s = tp.addStyle("general",null);
        StyleConstants.setAlignment(s,StyleConstants.ALIGN_LEFT);
        StyleConstants.setFontFamily(s, "SansSerif");
        StyleConstants.setFontSize(s, 12);
        doc.setLogicalStyle(0,s);

    }//end applyLogicalStyle


"Vella, John" wrote:

> I have an app that I'm considering allowing my users control of the fonts
> that the app uses to show various types of text. This has to run on Windows
> and Unix. Since the available fonts are so different between the platforms,
> my font chooser would have to only show symbolic font types(like
> "Monospaced", "Proportional", "Serif", etc), in addition to legal sizes and
> styles.
>
> Can anyone point me at some code that does this kind of thing?
>
> Thanks,
>
> John (using 1.3)
> _______________________________________________
> Swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/swing
import java.io.*;
import java.util.*;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
import javax.swing.undo.*;

/**
 *  Description of the Class
 *
 *@author     justin
 *@created    April 29, 2001
 */
class PrintFont {

    /**
     *  Constructor for the Test object
     *
     *@since
     */
    public PrintFont (){    
    }

    /**
     *  Description of the Method
     *
     *@since
     */
    public static void main(String args[]) {
        
        GraphicsEnvironment ge
                 = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontNames = ge.getAvailableFontFamilyNames();
        for (int i = 0; i < fontNames.length; i++) {
            System.out.println(fontNames[i]);
        }
    }
    
}

Reply via email to