如何在javafx8中加载css文件 [英] How load css file in javafx8

查看:360
本文介绍了如何在javafx8中加载css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javafx 8此代码不起作用

javafx 8 this code is not working

  scene.getStylesheets().add("appCssFile.css");

给予例外

Mar 25, 2014 12:21:20 PM com.sun.javafx.css.parser.CSSParser reportException
WARNING: Please report java.lang.NumberFormatException at:
Mar 25, 2014 12:21:20 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "appCssFile.css" not found. 

如何加载CSS?

推荐答案

您需要一个URL并调用toExternalForm才能将CSS文件加载到您的项目中.
为此使用ClassLoader:

You need an URL and call toExternalForm in order to load a css file into your project.
Use the ClassLoader for that:

scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());

这篇关于如何在javafx8中加载css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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