在StyleConstants.setFontFamily中使用.ttf

时间:2014-11-16 18:26:15

标签: java fonts jtextpane

所以我试图在项目中使用Apple II字体,但我很难搞清楚它。

我可以将它作为Font对象使用,但StyleConstants.setFontFamily使用params(MutableAttributeSet,String)。我怎样才能将这个.ttf变成setFontFamily可以使用的东西?

public class PageLayout implements ActionListener
{  
  ....
  static Font appleII = new Font("Calibri", Font.BOLD, 40); 
  ....
  public static void createAIIFont()
  {
    try
    {
      FileInputStream fis = new FileInputStream(new File("PrintChar21.ttf"))
      Font base = Font.createFont(Font.TRUETYPE_FONT, fis);
      appleII = base.deriveFont(Font.PLAIN, 24);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  public static void setText(String text)
  {
    SimpleAttributeSet attribs = new SimpleAttributeSet();  
    StyleConstants.setFontFamily(attribs, "//This is where the issue is");
    int len = pane.getDocument().getLength();
    pane.setCaretPosition(len);
    pane.setParagraphAttributes(attribs,true);
    pane.replaceSelection(text);
  }
}

0 个答案:

没有答案