如何动态更改javafx中滑块中的滑块拇指图标图像? [英] How can i dynamically change the slider thumb icon image in a slider in javafx?
本文介绍了如何动态更改javafx中滑块中的滑块拇指图标图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在FXML文件具有滑块:
滑块FX:ID = 滑块 了minHeight =20 minWidth = - 无限 prefWidth = 300.0
需要一个滑块图标图像从我的.java类更改,因为我可以使用 css
<更改拇指图标图像code> .slider .thumb {
-fx-background-image:url(your image);
... //更多定制
}
但我想改变来自.java类的图片
请建议..
谢谢
解决方案
你可以使用 Node#lookup()方法。
String IMAGE = getClass()。getResource(my-image.png)。toExternalForm();
StackPane thumb =(StackPane)slider.lookup(。thumb);
thumb.getChildren()。clear();
thumb.getChildren()。add(new ImageView(IMAGE));
NB:请注意,您需要在<$ c $之后调用此代码c> stage.show()让查找工作正常。
have slider in fxml file :
Slider fx:id="slider" minHeight="20" minWidth="-Infinity" prefWidth="300.0"
Want an slider thumb icon image to be change from my .java class as I can change the thumb icon image by using css
.slider .thumb{
-fx-background-image :url("your image");
...// more customization
}
But I want to change the image from .java class
Please suggest..
Thanks
解决方案
You can find thumb from Java code using Node#lookup() method.
String IMAGE = getClass().getResource("my-image.png").toExternalForm();
StackPane thumb = (StackPane)slider.lookup(".thumb");
thumb.getChildren().clear();
thumb.getChildren().add(new ImageView(IMAGE));
N.B.: Note you need to call this code after stage.show()
to have lookup working correctly.
这篇关于如何动态更改javafx中滑块中的滑块拇指图标图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文