我工作的一个项目,我想使用一个外部CSS文件使用JavaFX样式的垂直框和窗格和这样。
我用下面的一行来尝试将样式表添加到相应的场景:
scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
这给了我空指针,我读了关于这个问题的一些其他职位,发现这往往是由于它正试图从访问的类路径不是样式表。 下面是一个屏幕截图,让你一看就知道是不是这样的:
你会发现有Styles.css文件和style.css文件,我都尝试了不同的故障排除
我还发现,从人建议说,如果是在类路径,它应该这样访问:
scene.getStylesheets().add("style.css");
但是这样做是给我
Nov 04, 2018 9:24:10 PM com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "Styles.css" not found.
我愿意接受任何建议,我使用maven中的IntelliJ工作。
编辑:这是为进一步调查POM文件-
<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>