2015-01-10 43 views
1

我正在嘗試向GUI添加新自定義字體。 我將.tff文件添加到我的java項目中,但沒有成功使用它。這裏是我的代碼:將自定義字體添加到GUI SWT

Font font = new Font(shell.getDisplay(), "A.ttf", 12, SWT.NORMAL); 
    myText.setFont(font); 

注:我只能使用SWT。有誰知道如何安裝新的字體? 謝謝!

+0

對我答案的任何反饋? – Baz

+0

謝謝!運作良好。 –

回答

3

你需要加載字體首先將其提供給應用程序:

boolean isFontLoaded = shell.getDisplay().loadFont("A.ttf"); 

if(isFontLoaded) 
{ 
    Font font = new Font(shell.getDisplay(), "name of the font", 12, SWT.NORMAL); 
    myText.setFont(font); 
} 

Remeber再次處置Font,當你使用它來完成。

相關問題