Open Zeepheru opened 2 months ago
Another way to get the font name (at least on Windows) without using code is by:
.otf
/.ttf
/etc) in file explorerDetails
tabTitle
row in the Property
column and the name should be in the Value
column on the same row.Alternatively, you can just open the font file (double click) and then the name should be on the top at Font name: {font name}
.
Was pretty frustrating to figure out, with ChatGPT + Internet searches giving confusing contradicting info, so here's what worked for me if anyone wants to know:
1. Get your font files
Generally of the filetypes
.otf
or.ttf
. Create a new folderfonts
in yoursrc/main/resources
directory. Place the files there.2. Load fonts
In your
Main
class, or whatever extendsApplication
and is where your GUI runs from, importAnd add the following in the constructor:
<font-filename>
with the filename of the font you want to use, e.g.comic.ttf
that is present inresources/fonts
.v
is the default font size.3. Add fonts to CSS
Whenever you specify a font in CSS, simply replace that string with the name of the font you have loaded.
Note:
You might want to check the exact name of the font, since it can be different from the filename of that font. Make sure in the CSS sheet you use the actual name (e.g.
Montserrat SemiBold
orComic Sans MS
) and not the filename (Montserrat-SemiBold
orcomic
).You can obtain the names by:
Voila!
You can now show off to
the worldyour teammates your excellent taste in font choice.