Tomer Aronovsky
Tomer Aronovsky

Reputation: 135

Add Custom font to GUI SWT

I am trying to add a new custom font to a GUI. i added the .tff file to my java project but didn't succeed to use it. here is my code:

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

Note: I can use only SWT. Does anyone know how to install the new font? Thanks!

Upvotes: 1

Views: 1584

Answers (1)

Baz
Baz

Reputation: 36884

You'll need to load the font first to make it available to the application:

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 to dispose the Font again, when you're done using it.

Upvotes: 3

Related Questions