This code is not working in javafx 8
scene.getStylesheets().add("appCssFile.css");
I get the 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 the css ?
Adding it via the SceneBuilder or Hardcoding itIn the SceneBuilder view, click on the AnchorPane that was added first. In the Properties tab, under the 'JavaFX CSS' section, click on the 'Stylesheets' option. Select the CSS file, and that's it.
You can use CSS in JavaFX applications similar to how you use CSS in HTML. You should have a basic understanding of CSS to get the most out of this tutorial.
In Scene Builder, you can simulate the attachment of a style sheet to an application Scene by selecting Preview, then Scene Style Sheets, and finally choosing Add a Style Sheet or Open a Style Sheet option. This Preview command is useful when the “root” style class is defined in the style sheet.
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());
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With