简体   繁体   English

使用自定义字体及其路径

[英]Using custom fonts and their paths

I have looked in numerous places for the answer to this question and yet to find something that works. 我已经在很多地方寻找了这个问题的答案,却没有找到行之有效的方法。 I have a project in eclipse set up like so (I hope you can understand it): 我在Eclipse中建立了一个这样的项目(希望您能理解):

(Project)
src/package1/class1.cs
src/package2/class2.cs
JRE_SYSTEM_FILES/
res/font.ttf

So inside of the "res" folder, I have a font.ttf. 因此,在“ res”文件夹中,我有一个font.ttf。 I understand how to add the font to my program and use it using Font.createFont(), but What I cant understand is how to get the file path. 我知道如何将字体添加到程序中并通过Font.createFont()使用它,但是我不明白的是如何获取文件路径。 Everything I find assumes I have the path already which I don't. 我发现的所有内容都假定我已经拥有了我所没有的道路。 If anyone can help that would be greatly appreciated, and please If my formatting gets in the way of understanding the question please tell me. 如果有人可以帮助您,将不胜感激,如果我的格式妨碍理解该问题,请告诉我。

  1. use relative paths, run from the same place every time 使用相对路径,每次都从同一位置运行

  2. put font to the same folder where your class (that requires it) is, and call getClass().getResource("font.ttf"); 将字体放在您的类(需要它)所在的文件夹中,然后调用getClass().getResource("font.ttf"); .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM