I'm working on a project where I'd like to use an external CSS file with JavaFX to style the VBox and panes and such.
I've used the line below to try to add the style sheet to the respective scene:
scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
This gave me null pointers, I read some other posts on this issue and found that this is often due to the stylesheet not being in the class path that it is trying to be accessed from. Here is a screenshot that allows you to see that this is not the case:
You'll notice there is Styles.css and style.css, I tried both for different troubleshooting purposes
I also found suggestions from people saying that if it is in the class path, that it should be accessed as such:
scene.getStylesheets().add("style.css");
However doing so is giving me
Nov 04, 2018 9:24:10 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "Styles.css" not found.
I'm open to any suggestions, I'm working in IntelliJ using maven.
EDIT: Here is the pom file for further investigation -
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.almasb</groupId>
<artifactId>CashMachine</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<source.version>1.8</source.version>
<!-- plugins -->
<maven.compiler.version>3.3</maven.compiler.version>
<maven.shade.version>2.4.2</maven.shade.version>
<!-- dependencies -->
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${source.version}</source>
<target>${source.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.almasb.atm.CashMachineApp</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>