我在FXML中使用fitWidth
并preserveRatio
调整了它的大小ImageView
,但是图像没有缩放到它,而是显示了它的完整大小(在我的情况下太大)。如何使用FXML或CSS设置图像的大小?
XML文件
<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");
}
我不需要JavaFX代码解决方案,因为我想将样式保留在fxml和css中。
如果在FXML或CSS中确实无法做到这一点,那么我会同意使用Java,在这种情况下,请发表评论。
FXML中的图像
当我尝试
<ImageView id="buttonDownImage" fitHeight="40.0" fitWidth="40.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="resources/down.png" />
</image>
</ImageView>
然后有一段java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
时间,我确定文件在那里(css可以找到它),并且甚至建议resources
在URL中以IntellJ自动完成功能开始。
如果图片太大,那么请调整它们的尺寸!解决方案不好,但总比没有好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句