FileDocCategorySizeDatePackage
FontLoadingDemo.javaAPI DocExample1111Mon Jan 09 11:02:00 GMT 2006None

FontLoadingDemo

public class FontLoadingDemo extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        try {
            // get font from path in args[0]
            if (args.length < 1) {
                System.out.println ("usage: FontLoadingDemo path-to-ttf");
                return;
            }
            File f = new File (args[0]);
            FileInputStream in = new FileInputStream (f);
            Font dynamicFont =
                Font.createFont (Font.TRUETYPE_FONT, in);
            Font dynamicFont32Pt = 
                dynamicFont.deriveFont (32f);

            // draw something with it
            JLabel testLabel =
                new JLabel ("Dynamically loaded font \"" + 
                            dynamicFont.getName() + "\"");
            testLabel.setFont (dynamicFont32Pt);
            JFrame frame = new JFrame ("Font Loading Demo");
            frame.getContentPane().add (testLabel);
            frame.pack();
            frame.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }