id="back" prefHeight="400.0" prefWidth="600.0" style="-fx-background-image: url('file:com/example/test/background.png');" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.test.Play">
图片用绝对路径可以,但是怎么能设置成相对路径
绝对路径如下:/Users/oneone/Downloads/SpaceAsteroid/src/main/resources/com/example/test/background.png
最好不要这样添加背景图,可以用其它组件,或者在代码中添加。这种方式总有奇奇怪怪的问题
url='@src/main/resources/com/example/test/background.png' 试试这样,不行就只能全路径了