fontloadingdemo.java

来自「oraily的Swing hacks code」· Java 代码 · 共 35 行

JAVA
35
字号
import java.io.*;import java.awt.*;import javax.swing.*;public class FontLoadingDemo {    public static void main (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();        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?