I used fitWidth
and preserveRatio
to size the ImageView
in the FXML, but the image does not scale to it but instead shows its full size (too big in my case). How do I set the size of the image using FXML or css?
FXML
<Button
fx:id="buttonUp"
GridPane.columnIndex="0"
GridPane.rowIndex="0"
onAction="#buttonUp">
<graphic>
<ImageView fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
</ImageView>
</graphic>
</Button>
CSS
#buttonUp {
-fx-graphic: url('up.png');
}
#buttonUp:pressed {
-fx-graphic: url("up_pressed.png");
}
I don't want a JavaFX code solution because I want to keep my styling in the fxml and css.
If this really isn't possible in FXML or css then I'd concede in doing it with java, in that case just leave a comment.
Image in FXML
When I try
<ImageView id="buttonDownImage" fitHeight="40.0" fitWidth="40.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="resources/down.png" />
</image>
</ImageView>
Then there follows an java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
while I'm sure the file is there (the css could find it) and the IntellJ autocomplete even suggested to start with resources
in the url.