我想更改按钮内图标的大小。图像的大小为 512 x 512,我想调整为 16x16。那么,使用 javaFX CSS 实现这一目标的最佳方法是什么。
这是我到目前为止所做的:
#btnCancel.button {
-fx-graphic: url("/img/close.png") ;
-fx-graphic-size:16px 16px ; ( I think this property not exist in javafx css)
}
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用。
I am not aware of any css property that can be used directly to set the -fx-graphic's size but you can achieve similar results using -fx-background-image property. This will allow you to set width and height values using -fx-background-size.
You can access BackgroundSize's javadoc from this link
.logButton {
/*
-fx-graphic: url(images/log2.png);
-fx-graphic-size:16px 16px;
*/
-fx-background-image: url(images/log2.png);
-fx-background-size: 64px 64px;
-fx-background-repeat: no-repeat;
-fx-background-position: center;
}
Run Code Online (Sandbox Code Playgroud)
See in action
Using -fx-graphic
Using -fx-background-image with -fx-background-size