下图显示了我的问题:
如您所见,如果我通过“场景”构建器打开view.fxml,则会显示按钮图标,但是当我通过IDE(在前台运行)运行程序时,它们不会显示。< / p>
我认为我应该改变路径,但我仍然希望能够使用场景构建器。 从我的IDE开始,我感到高兴只是让它工作。
有趣的是,如果改变路径,我的代码辅助会给我警告/错误。
我发布我的.fxml和.css只是为了彻底:
<?scenebuilder-stylesheet ../content/style.css?>
<Pane prefHeight="379.0" prefWidth="616.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="controller.Controller">
<children>
<ColorPicker layoutX="16.0" layoutY="36.0" />
<MenuBar layoutX="0.0" layoutY="0.0" maxWidth="-Infinity" minHeight="21.000099999997474" prefHeight="21.000099999997474" prefWidth="616.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<Button id="squareBtn" layoutX="67.0" layoutY="77.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="32.0" text="" />
<Button id="circleBtn" layoutX="16.0" layoutY="77.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="32.0" style="" text="" />
<Button id="triangleBtn" layoutX="16.0" layoutY="119.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="32.0" style="" text="" />
<Button id="lineBtn" layoutX="67.0" layoutY="119.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="32.0" style="" text="" />
<Separator layoutX="110.0" layoutY="21.0" orientation="VERTICAL" prefHeight="360.0" />
</children>
</Pane>
#circleBtn {
-fx-background-image: url("circle.png");
-fx-background-size: 32 32;
-fx-background-repeat: no-repeat;
-fx-background-position:center;
}
#squareBtn {
-fx-background-image: url("square.png");
-fx-background-size: 32 32;
-fx-background-repeat: no-repeat;
-fx-background-position:center;
}
#triangleBtn {
-fx-background-image: url("triangle.png");
-fx-background-size: 32 32;
-fx-background-repeat: no-repeat;
-fx-background-position:center;
}
#lineBtn {
-fx-background-image: url("line.png");
-fx-background-size: 32 32;
-fx-background-repeat: no-repeat;
-fx-background-position:center;
}