Java字体问题
假设我有一个 Swing JComponent,并且我为该 JComponent 的文本设置了一个 Font。我构建项目并创建项目的 .jar 文件。现在,如果我从另一台未安装字体的计算机上运行这个 jar 文件,会发生什么? jar 会自动安装字体还是我需要进行某种检查才能做到这一点?谢谢。
Say I have a Swing JComponent and I set a Font for the text of that JComponent. I build the project and create a .jar file of my project. Now, If I run this jar file from another computer where the Font is not install, what will be happen? Will the jar automatically install the Font or I need to make some kind of checking to do that? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要使用该特定字体,则必须在运行 jar 文件之前确保它已安装在计算机上,或者自行加载。没有任何东西会自动为您安装字体。您可以使用以下代码检索可用字体的列表:
或者,您可以使用自己加载和注册字体
您应该检查
registerFont
的返回代码并捕获/处理抛出的异常创建字体
。If you need to use that specific font, you'll have to make sure it's installed on the machine before your jar file is run, or load it yourself. There's nothing that will automatically install the font for you. You can retrieve the list of available fonts using this code:
Alternatively, you can load and register the font yourself using
You should check the return code of
registerFont
and catch/deal with the exceptions thrown bycreateFont
.不,没有任何自动方法。您必须手动安装字体,但是您可以使用以下方式获取可用字体:
No there isn't any automatic method. You have to install font manually however you may get the available fonts using,