如何加载逻辑字体物理字体? (制作 JComboBox 字体选择器)
此问题的后续问题: Swing 字体名称不匹配? (制作字体选择器,并尝试在 JComboBox 中显示默认系统字体)
看来有逻辑字体和物理字体。逻辑字体是: Serif、SansSerif、等宽字体、Dialog 和 DialogInput。
这些字体是动态的,它们各自的物理字体(它们在程序执行期间表示的字体)是在程序加载时决定的。
我需要访问这些逻辑字体的物理字体。
我的第一个想法是尝试加载这些文件: http://download.oracle.com/ javase/6/docs/technotes/guides/intl/fontconfig.html#loading
使用如下内容: http://www.rgagnon.com/javadetails/java-0434.html
public static Properties load(String propsName) throws Exception {
Properties props = new Properties();
URL url = ClassLoader.getSystemResource(propsName);
props.load(url.openStream());
return props;
}
然后从这些属性文件中获取物理字体。
但是,当我尝试使用第一个文件中的名称加载属性时,我刚刚收到 NullPointerExceptions(未找到它们,但我已检查并实际上在我的系统上找到了它们)。我不知道为什么我会得到这个,但无论如何,我不禁想一定有一种更简单的方法来做到这一点?
Followup question from this one:
Swing font names do not match? (Making a font chooser, and am trying to display the default system font in a JComboBox)
It appears there are logical and physical fonts. The logical fonts are:
Serif, SansSerif, Monospaced, Dialog, and DialogInput.
These fonts are dynamic, and their respective physical font (the font that they will represent during program execution) are decided when the program loads.
I need to access the physical font of these logical fonts.
My first idea was to try and load these files:
http://download.oracle.com/javase/6/docs/technotes/guides/intl/fontconfig.html#loading
by using something like this:
http://www.rgagnon.com/javadetails/java-0434.html
public static Properties load(String propsName) throws Exception {
Properties props = new Properties();
URL url = ClassLoader.getSystemResource(propsName);
props.load(url.openStream());
return props;
}
and then getting the physical fonts from these properties files.
However, I am just getting NullPointerExceptions when trying to load the properties using the names in the first file (they are not found, but I have checked and actually found them on my system). I don't know why I am getting this, but regardless of that, I can't help to think there must be an easier way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)