怎么将JLabel的字体设置成我自己下载的字体

解决方案 »

  1.   

    java.awt.Font类提供了
    static Font  createFont(int fontFormat, File fontFile)
              Returns a new Font using the specified font type and the specified font file.
    static Font  createFont(int fontFormat, InputStream fontStream)
              Returns a new Font using the specified font type and input data.
      

  2.   

            Font font = null;
            String fName = "A.ttf"; //Test
            try {
                InputStream is = DemoFonts.class.getResourceAsStream(fName);
                font = Font.createFont(Font.TRUETYPE_FONT, is);
            } catch (Exception ex) { 
                ex.printStackTrace(); 
                System.err.println(fName + " not loaded.  Using serif font.");
                font = new Font("serif", Font.PLAIN, 24);
            }
            return font;
      

  3.   


    JLabel label = new JLabel();
    label.setFont(new Font("Serif", Font.PLAIN, 12));
      

  4.   

    Swing可以查询系统字体, 所以可以先安装字体, 然后设置字体