问题
javafx 8 this code is not working
scene.getStylesheets().add("appCssFile.css");
give Exception
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.
How can i load css ?
回答1:
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());
回答2:
For those who can't find css the way from accepted answer use classLoader:
getClass().getClassLoader().getResource("css/style.css").toExternalForm()
If you use maven it will find your css under resources/css/
dir.
回答3:
Simply add package name with .css file.
Your code will look like this:
scene.getStylesheets().add("sample/appCssFile.css");
回答4:
In my case ,I want to load a css file from disk and I do it as this article said and it worked for me. code snippet as follow:
scene.getStylesheets().add("file:///E:/csse2002-7023/src/csse2002/block/world/main.css")
来源:https://stackoverflow.com/questions/22627579/how-load-css-file-in-javafx8