Javafx css按钮图形调整大小
问题描述:
我想更改按钮内图标的大小。 图像的大小为512 x 512,我想调整为16x16。 那么,使用javaFX CSS实现这一点的最佳方式是什么?Javafx css按钮图形调整大小
这里是我做直到如今
#btnCancel.button {
-fx-graphic: url("/img/close.png") ;
-fx-graphic-size:16px 16px ; (I think this property not exist in javafx css)
}
但这不是我的作品。
答
我不知道,你可以直接使用设置-fx图形大小CSS属性的,但你可以使用-fx背景图像特性实现类似。您可以使用-fx-background-size来设置宽度和高度。
你可以从这个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;
}
访问的javadoc见行动
使用-fx图形
使用-fx背景图像与-fx背景大小
答
我知道这个问题是关于CSS的,但对于其他程序员在那里,想做到这一点java代码,并找到这个线程,这里是我用java代码做的解决方案。 (而不是要求一个新的问题)
Platform.runLater(() -> {
InputStream input = getClass().getResourceAsStream("/resources/images/close-512x512.png");
//set the size for image
Image image = new Image(input, 16, 16, true, true);
ImageView imageView = new ImageView(image);
myButton.setGraphic(imageView);
});
此[问题](http://*.com/questions/30098116/javafx-css-button-with-image-how-to-define-the-size图像)没有被接受的答案,但它可能对你有帮助。 – Peter
处理此问题的最佳方法是提供16x16图标而不是512x512图标。 – jewelsea