javafx @ font-face css error" loadStyleSheetUnprivileged" [英] javafx @font-face css error "loadStyleSheetUnprivileged"

查看:159
本文介绍了javafx @ font-face css error" loadStyleSheetUnprivileged"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此方法在JavaFx css中加载自定义字体

I'm trying to load a custom font in JavaFx css using this method

@font-face {
    font-family: 'Roboto';
    src: url('fonts/Roboto-Medium.ttf');
}

我已经用正确的路径完成了所有事情,但我得到了此错误

I've done every thing proper with the correct path but I'm getting this error

Nov 28, 2015 4:49:18 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
INFO: Could not load @font-face font [file:/C:/Users/RootUser/Desktop/Java8%20projects/RemoteViewer/out/production/JavaFxApplication/application/fonts/Roboto-Medium.ttf]

这是我的项目结构截图

注意我正在使用intellij Idea作为我的IDE.Thanks提前。

Note I'm using intellij Idea as my IDE.Thanks in advance.

推荐答案

这是JavaFX(8)中的一个错误。如果字体文件的路径名中有空格,则不会加载,并抛出异常,就像发生在你身上一样。

This a bug in JavaFX (8). If there's a space in the font file's pathname, it won't load, and throw an exception, as it happened in with you.

这意味着我们不应该从CSS文件加载字体,除非我们确定文件路径不包含任何空格。

This means that we shouldn't load fonts from a CSS file, unless we're sure the file path won't contain any spaces.

有一种更好,更安全的方式来加载字体(〜首先行内 main()):

There is a better, safe way to load fonts (~first line inside main()):

Font.loadFont(getClass().getResourceAsStream("/font.ttf"), 16);

这篇关于javafx @ font-face css error" loadStyleSheetUnprivileged"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆